I created a list view which extends ListActivity and I have a search field at the top of the page
but I don't know how to write it , I want a search like search contact (type just only 1 char and listview will change, don't have to press any button)
please give me some example code
thanks
I think you should see this
If you are currently using a CursorAdapter to display the List, than you can create a custom CursorAdapter which does filtering automatically as you type keys. The following webpage provides an excellent example of this: http://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/
Good luck!
Create a AutoCompleteTextView in your Layout,then put this in your class file,
AutoCompleteTextView txtPhoneNo = (AutoCompleteTextView) findViewById(R.id.txtPhoneNo);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, name_Val);
txtPhoneNo.setAdapter(adapter);
where name_Val is the String Array that contains "DATA"
Related
I have a TextInputLayout with style ExposedDropdownMenu. this TextInputLayout contains an AutoCompleteTextView.
I can add a list item inside this AutoCompleteTextView using an adapter.
mLightSensorGainTextInput = (AutoCompleteTextView) findViewById(R.id.paramLightSensorGain);
String[] gainStrArray = new String[] {"1", "2"};
ArrayAdapter<String> gainAdapter = new ArrayAdapter<>(this, R.layout.version_list_item, gainStrArray);
mLightSensorGainTextInput.setAdapter(gainAdapter);
I would like to set one value displayed when I click a "setDefaultButton" but I have always the initial view:
I tried :
mLightSensorGainTextInput.setListSelection(0);
mLightSensorGainTextInput.setSelection(0);
but none of the 2 methods shows the value expected which is : 1.
Do you have any suggestion?
Best regards
Mich
Please here is more informations about what I expect. Only last operation (default button) does not work.
Try setText():
mLightSensorGainTextInput.setText("xxx");
As your items are text-based, you can get the first item from the adapter by autoCompleteTextView.getAdapter().getItem(position); then to make it the current selection; set the text of the autoCompleteTextView to that item: mLightSensorGainTextInput.setText((mLightSensorGainTextInput.getAdapter().getItem(0)).toString());
The solution is to use the filter:
mLightSensorGainTextInput.setText("1", false);
I have Auto-complete Box in Android, i am filling this Auto-complete Box with the names of Some list retrieved from the Server.
Suppose i Have ABC, XYZ, PQR, ABCC, ABCCD etc... Now on First Suggestion when i type AB: It should give me ABC, ABCC, ABCCD. Now i have selected ABC..
(Autocomplete in multivalue separated by ;)
NOw when i write ABC: It Again give ABC, ABCC, ABCCD..
Result i Want: on ABC select should be removed from the Autocomplete list. so Next suggestion should be ABCC, ABCCD only not ABC.
Please Help me out
Thanks in Advance..
Code from comment below:
myAutoComplete = (MultiAutoCompleteTextView) findViewById(R.id.talksender);
myAutoComplete.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, names));
You need to keep track of the selected items.
When creating the filtered list you need to filter by the string typed into the EditText AND by the items already selected.
For filtering your ArrayAdapter you need to:
Create a Filter implementaion which performs the filtering based on the EditText input AND the already selected items.
Override your ArrayAdapter's getFilter() method to return your custom Filter implementation
I have a control Gridview and an XML that must populate the GridView.
XML is:
<?xml version='1.0' encoding='iso-8859-1' ?>
<MEDS>
<MED>
<NOM>GELOCATIL</NOM>
<COD>12812931</COD>
</MED>
<MED>
<NOM>OTRO GELOCATIL</NOM>
<COD>1281293222</COD>
</MED>
</MEDS>
How do I create a Cursor for this? Or alternatives, pls?
Bye.
gridViewObj.setListAdapter(Adapters.loadAdapter(this, R.xml.contacts));
gridViewObj : GridView Object
xml source : R.xml.contacts
[for More info click here][1]
[1]: https://developer.android.com/resources/samples/XmlAdapters/index.html
I think the right answer is to do an adapter class specific for this xml. But it is more complicated and takes more time. #Sravan has not provided the code so I am obliged to give this answer as right.
We can look for a creative and easy solution although not optimized.
If the case is that you only need 1 or 2 fields of the XML, which can be usual, because you're showing a list that is clickable, so you need only to show to title and to give a substantial information (id for example or use the text of the title itself) so that when you click, takes you to another activity.
So the easiest is to use an ArrayAdapter, a TreeMap and an ArrayList
TreeMap<String, String> xmlMapping;
//here you add the values of the xml with Xpath to the variables clave and valor
xmlMapping.put(clave,valor);
ArrayList<String> lista=new ArrayList<String>();
for(Map.Entry<String, String> entry: xmlMapping.entrySet())
{
lista.add(entry.getKey());
}
ArrayAdapter ad=new ArrayAdapter<String>(this.activity.getApplicationContext(),
R.layout.gridrow,R.id.colName,
lista);
grid.setAdapter(ad);
Then to know which element has been clicked the only thing is to iterate through the xmlMapping or take the value of the ArrayList.
I want to create a AutoCompleteTextView in android. The problem is that I want to show whole list of data when user selects AutoCompleteTextView and start filtering data as user types the letters.Please help me in doing this.
Well here is an way how you can do that,
declare an String array -
String[] array = new String[]{"first","second","third","fourth"};
Now, initialize the Adapter with the source.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,array);
Finally fetch the AutoCompleteTextView id from your xml and set the adapter.
AutoCompleteTextView mView = (AutoCompleteTextView)
findViewById(R.id.myAutoTextView);
mView.setAdapter(adapter);
I have been scouring the Internet for a way to use an input box at the top of the page, and have an add & remove button.
I want the EditText to write to the ListView, which in turn writes the list to a .txt-file.
I have tried breaking this down into multiple small sections of just simple things like
getting the input from the EditText to post to a TextView.
Organizing a ListView
writing to a file and
reading from a file.
If you have any advice about how to get the ListView to go from the EditText greatly helpful.
The best way to do this is to have an ArrayList<String> to store your Strings from the TextView, and in turn have that ArrayList<String> feed into the ListView. For example, for your Add button handler:
// Declare our variables
ArrayList<String> myStringList = new ArrayList<String>();
// OnClickListener stuff for Add button
..
myStringList.add(myEditText.getText().toString());
myListView.setListAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, myStringList));
..
// Close OnClickListener stuff
Make sure you refresh your list adapter afterwards to show the new values. Likewise if you're deleting, use myStringList.remove(index) to remove that string from the list and refresh the array adapter. As for writing to a text file, have a look at this thread.