Site icon C1CTech

Android MultiAutoCompleteTextview

<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Multi AutoComplete Textview<&sol;strong><&sol;span><&sol;h3>&NewLine;<p>An editable text view&comma; extending <strong><span style&equals;"color&colon; &num;008000&semi;">AutoCompleteTextView<&sol;span><&sol;strong>&comma; that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing&period;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;008000&semi;">MultiAutoCompleteTextView<&sol;span><&sol;strong> can hold multiple string words value at single time&period; These all values are separated by comma&lpar;&comma;&rpar;&period;<&sol;p>&NewLine;<p>Get <span style&equals;"color&colon; &num;0000ff&semi;"><strong>GITHUB<&sol;strong><&sol;span> code from <span style&equals;"color&colon; &num;0000ff&semi;"><a style&equals;"color&colon; &num;0000ff&semi;" href&equals;"https&colon;&sol;&sol;github&period;com&sol;arunk7839&sol;MultiSelectionAutoCompleteTextview"><strong>Here<&sol;strong><&sol;a><&sol;span>&period;<&sol;p>&NewLine;<p><span class&equals;"embed-youtube" style&equals;"text-align&colon;center&semi; display&colon; block&semi;"><amp-youtube data-videoid&equals;"stNyalERgZk" data-param-rel&equals;"1" data-param-showsearch&equals;"0" data-param-showinfo&equals;"1" data-param-iv&lowbar;load&lowbar;policy&equals;"1" data-param-fs&equals;"1" data-param-hl&equals;"en-US" data-param-autohide&equals;"2" data-param-wmode&equals;"transparent" width&equals;"1200" height&equals;"675" layout&equals;"responsive"><a href&equals;"https&colon;&sol;&sol;www&period;youtube&period;com&sol;watch&quest;v&equals;stNyalERgZk" placeholder><amp-img src&equals;"https&colon;&sol;&sol;i&period;ytimg&period;com&sol;vi&sol;stNyalERgZk&sol;hqdefault&period;jpg" alt&equals;"YouTube Poster" layout&equals;"fill" object-fit&equals;"cover"><noscript><img src&equals;"https&colon;&sol;&sol;i&period;ytimg&period;com&sol;vi&sol;stNyalERgZk&sol;hqdefault&period;jpg" loading&equals;"lazy" decoding&equals;"async" alt&equals;"YouTube Poster"><&sol;noscript><&sol;amp-img><&sol;a><&sol;amp-youtube><&sol;span><&sol;p>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Creating New Project<&sol;span><&sol;strong><&sol;h3>&NewLine;<ol>&NewLine;<li>In Android Studio&comma; go to<span style&equals;"color&colon; &num;008000&semi;"> <strong>File <&sol;strong><strong>&Implies;<&sol;strong><strong> New Project<&sol;strong><&sol;span> and fill all the details required to create a new project&period; When it prompts to select a default activity&comma; select <span style&equals;"color&colon; &num;008000&semi;"><strong>Blank Activity<&sol;strong><&sol;span> and proceed&period;<&sol;p>&NewLine;<&sol;li>&NewLine;<li>&NewLine;<p>Open<span style&equals;"color&colon; &num;008000&semi;"> <strong>activity&lowbar;main&period;xml<&sol;strong><&sol;span> in which I have add  one <strong><span style&equals;"color&colon; &num;008000&semi;">MultiAutoCompleteTextview<&sol;span><&sol;strong> with following basic properties&period;<&sol;p>&NewLine;<&sol;li>&NewLine;<&sol;ol>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>activity&lowbar;main&period;xml<&sol;strong><&sol;span><&sol;p>&NewLine;<&excl;-- WP QUADS Content Ad Plugin v&period; 3&period;0&period;1 -->&NewLine;<div class&equals;"quads-location quads-ad2" id&equals;"quads-ad2" style&equals;"float&colon;none&semi;margin&colon;0px&semi;">&NewLine;&NewLine;<&sol;div>&NewLine;&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;android&period;support&period;constraint&period;ConstraintLayout xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; xmlns&colon;tools&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;tools"&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine; android&colon;padding&equals;"18dp"&NewLine; tools&colon;context&equals;"com&period;example&period;lenovo&period;multiautocompletetextview&period;MainActivity"&gt&semi;&NewLine;&NewLine; &lt&semi;MultiAutoCompleteTextView&NewLine; android&colon;id&equals;"&commat;&plus;id&sol;mac&lowbar;tv"&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; android&colon;background&equals;"&commat;android&colon;color&sol;holo&lowbar;blue&lowbar;light"&NewLine; android&colon;textSize&equals;"25sp" &sol;&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;android&period;support&period;constraint&period;ConstraintLayout&gt&semi;&NewLine;<&sol;pre>&NewLine;<p>3&period;Now open  <span style&equals;"color&colon; &num;008000&semi;"><strong>MainActivity&period;java<&sol;strong><&sol;span> and and add the below code&period; The following code snippet shows<br &sol;>&NewLine;how to create a text view which suggests various countries names while the user is typing&colon;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>MainActivity&period;java<&sol;strong><&sol;span><br &sol;>&NewLine;<code><&sol;code><&sol;p>&NewLine;<pre>package com&period;example&period;lenovo&period;multiautocompletetextview&semi;&NewLine;&NewLine;import android&period;graphics&period;Color&semi;&NewLine;import android&period;support&period;v7&period;app&period;AppCompatActivity&semi;&NewLine;import android&period;os&period;Bundle&semi;&NewLine;import android&period;widget&period;ArrayAdapter&semi;&NewLine;import android&period;widget&period;MultiAutoCompleteTextView&semi;&NewLine;&NewLine;public class MainActivity extends AppCompatActivity &lbrace;&NewLine;&NewLine; String&lbrack;&rsqb; country &equals; &lbrace;"Australia"&comma; "Albania"&comma; "Belgium"&comma; "Bhutan"&comma; "Canada"&comma; "China"&comma; "India"&rcub;&semi;&NewLine;&NewLine; &commat;Override&NewLine; protected void onCreate&lpar;Bundle savedInstanceState&rpar; &lbrace;&NewLine; super&period;onCreate&lpar;savedInstanceState&rpar;&semi;&NewLine; setContentView&lpar;R&period;layout&period;activity&lowbar;main&rpar;&semi;&NewLine;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&sol;&sol;We can use any of the built&lowbar;in android layout simple&lowbar;list&lowbar;item&lowbar;1 and select&lowbar;dialog&lowbar;item<&sol;strong><&sol;span>&NewLine; ArrayAdapter&lt&semi;String&gt&semi; adapter &equals; new ArrayAdapter&lt&semi;String&gt&semi;&lpar;this&comma; android&period;R&period;layout&period;simple&lowbar;list&lowbar;item&lowbar;1&comma; country&rpar;&semi;&NewLine;&NewLine; MultiAutoCompleteTextView mac&lowbar;tv &equals; &lpar;MultiAutoCompleteTextView&rpar; findViewById&lpar;R&period;id&period;mac&lowbar;tv&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Start character for search<&sol;span><&sol;strong>&NewLine; mac&lowbar;tv&period;setThreshold&lpar;1&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Setting adapter<&sol;span><&sol;strong>&NewLine; mac&lowbar;tv&period;setAdapter&lpar;adapter&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; set tokenizer that distinguish the various substrings by comma<&sol;span><&sol;strong>&NewLine; mac&lowbar;tv&period;setTokenizer&lpar;new MultiAutoCompleteTextView&period;CommaTokenizer&lpar;&rpar;&rpar;&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;Setting textcolor after selection<&sol;span><&sol;strong>&NewLine; mac&lowbar;tv&period;setTextColor&lpar;Color&period;BLUE&rpar;&semi;&NewLine; &rcub;&NewLine;&rcub;&NewLine;&NewLine;&NewLine;<&sol;pre>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Now when you run the app it will look like this&colon;<&sol;strong><&sol;span><&sol;h5>&NewLine;<p><img class&equals;"aligncenter wp-image-183 " src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2018&sol;03&sol;Screenshot&lowbar;2018-03-06-19-04-091&period;png" alt&equals;"" width&equals;"456" height&equals;"760" &sol;><&sol;p>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;&NewLine;

Exit mobile version