I am new to android development and i am using MultiAutoCompleteTextView in my APP and following is code.
public TextView autoSelected;
String[] countries = {"India","USA","Canada","Indonesia","Belgium", "France", "Italy", "Germany", "Spain"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MultiAutoCompleteTextView autoCompleteTextView = (MultiAutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,countries);
autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
First Problem and main problem
TextView is getting duplicate values means same country is showing in TextView again and again. Example: i can select USA from autocomplete n number of times and it is showing n times in text field.
I want if i already selected specific value from suggestion, in that case either it should not visible in suggestions or it should not be visible in TextView.
Second issue
I want to customize design of selected values that are currently in TextView like with background and close sign attached to it.
Related
As a user when I start typing into the search field I want to see some autocomplete options based on matching terms in the paragraph(String) so that I don't have to type really long terms using a tiny phone keyboard.
Note:
The Suggestion will come from particular content or String
The following link is for the Android Developers forum that should get you started along. Link : https://developer.android.com/reference/android/widget/AutoCompleteTextView.html
The example as provided in the link for creating text view which suggests various countries names while the user is typing:
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
//initialise the adapter for give n array of strings to be searched with
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView autotextView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
//set the adapter for the Autocomplete TextView
autotextView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}
Try this, Make a layout containing autoCompleteTextView
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
then in java code list all the suggestions in the array,
String[] suggestions ={"Android","java"};
//or get it via array.xml of res, using
//String[] suggestions = getResources().getStringArray(R.array.suggarray);
text=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,suggestions);
text.setAdapter(adapter);
text.setThreshold(1);
I've following requirement and Since I'm new to this Android stuff, I'm not able to figure it out.
I've two Edit text fields for a driverName and a vehicleNumber. But these values shouldn't be new i.e When I try to enter driverName in particular EditText field, I should get all the driverNames populated so that I can choose one them. Same for vehicleNumber too.
For this I already have data of driverName and Vehicle Number But my problem is how to populate them while entering in fields ??? Any good answer will be appreciated :)
Thank You.
You should go AutoCompleteTextView as What M D suggested. Example is
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}
i'm creating an Application where there is a part where user needs to enter the state,city and district in an Edittext.
while entering the state I need to show some possibly matching suggestions with the letters that are typed in the edittext.
I have searched a lot and couldnt find anything useful as per my requirements..
So how do i go about this?? the suggestions of can come from a sqlite database table... if anybody knows any good example or can guide me through the coding please help...
i have no idea how to do it...
use autocomplete textview and then get your country/state list and set in adapter.
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}
setThreshold(int threshold)
Specifies the minimum number of characters the user has to type in the edit box before the drop down list is shown.
AutoCompleteTextView might help you
try it out here
I have a list of cities(around 2500 of them). I want the user to get auto suggestions when he types in the edittextbox from that list. How is this achieved? I have searched Google through and through but cannot find any tutorial about this. Would really appreciate any help.
Thanks.
You should use AutoCompleteTextView to achieve this.
The following code snippet shows how to create a text view which suggests various countries names while the user is typing:
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}
Use AutoCompleteTextview, here is a tutorial from the development site (bottom of the page). http://developer.android.com/guide/topics/ui/controls/text.html
You can use "Filter" for searching from your other list.
Implement your own filter [MyFilter extends Filter] and override "FilterResults performFiltering(CharSequence prefix)" and "void publishResults(CharSequence constraint,FilterResults results)" methods to implement your own searching logic on your own data (country list).
Add a getMyFilter() method in your adapter which will return a "new myFilter"
Add a "TextWatcher" to your "EditText"
Inside "onTextChanged()" method of the TextWatcher, get your filter by calling myAdapter.getMyFilter()". On that filter, call "myFilter.filter(myTypedString)".
After filtering "void publishResults(CharSequence constraint,FilterResults results)" method will get called. Inside that, change your actual adapter data to refresh your UI.
My senior project group is developing an android application and we would like to be able to implement something like the example found in this screenshot:
What we have right now is a Spinner drop down, the very first default will be "Add faculty...". Once you create that faculty, it will be selectable in the spinner, but in case a class has more than one faculty(ie: Professor, Teaching Assistant), we want to be able to add more than one spinner using the +/- buttons like you see here.
Any examples or leads in the right direction would be most appreciated.
Create two variable of ArrayAdapter and Arraylist of string to be global.
ArrayList<String> art;
ArrayAdapter<String> adapter;
And then in onCreate initialize the spinner as below
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
s1 = (Spinner) findViewById(R.id.spinner);
art=new ArrayList<String>();
art.add("professer");
adapter = new ArrayAdapter<String>(
this,android.R.layout.simple_spinner_item,art);//Items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
}
And then in button click , add new elements in array and notify the adapter
public void btn_click(View v)
{
art.add("Technical Assistant");
adapter.notifyDataSetChanged();
}