Reputation: 792
i want to implement an onclicklister to autocompletetextview having results from database table.
I've googled it but didnt get what exactly i want. stackoverflow link.
in my autocompletetetextview i'll show the name of the user and if you click on the selected item it should open the user details page, for this i've get username and id from user table but i have to display only name in autocompletetextview with that userid it sends the request and opens the user details screen.
Thanks in advance.
Upvotes: 0
Views: 881
Reputation: 8079
Maintain two arrays.. one for username and the other for id.. now i think you know how to get any value from a database...Put an edittext field and a listview below that edittext..The results will be displayed in that listview... Now create a thread which will continuously check the string in the edittext.. like this..
s1="";
s2=youredittext.getText().toString();
new Thread(new Runnable() {
public void run() {
while(bool){
s2=youredittext.getText().toString();
if(s1!=s2 && s2.length()>=1){
s1=s2;
//here search the database for the name starting with the string in s1 and get the user name and id fields..and populate the arrays...
}
runOnUiThread(new Runnable() {
public void run() {
adapter.clear();<--- this will clear the list every time a new letter is added or removed from the edittext.. and add relevent items..
for(int z=0;z<namesarray.length;z++){
adapter.add(namesarray[z]);
}
adapter.notifyDataSetChanged();
}
});
}}).start();
and when you click on any item get the position of item in that list.. and the item at that index in ids array will be the corresponding id..
Upvotes: 1