Question

I have one autocompleteTextview, where i am loading a string array in to it.. so that i can search the data by typing the firstletter .Now i need to load a list on selecting each item in autocomplete textview .. How is it possble?

this is my autocompletetextview

autocomplete = (AutoCompleteTextView) customView.findViewById(R.id.myautocomplete);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,
                    android.R.layout.simple_dropdown_item_1line, ENTON_WEB);
autocomplete.setAdapter(adapter);

Thanks in advance

Was it helpful?

Solution

String s1="xcv";
String s2;
String [] search=new String[20];<---- this is your search list
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ac=(EditText)findViewById(R.id.editText1);
    ListView lv=(ListView)findViewById(R.id.listView1);
    //ac.setThreshold(3);
    //l.add("pp");
    s2=ac.getText().toString();
    adapter=new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1,
            l);
            //adapter.add("pp");
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(mMessageClickedHandler);
    new Thread(new Runnable() {
          public void run() {

          while(infra){

              s2=ac.getText().toString();
          if(s1!=s2 && s2.length()>=1){

              s1=s2;
for(int=0;i<20;i++)
{
int index=search[i].index(s1);
if(index >-1)
{
 lst.add(search[i])<----- lst is the arraylist of strings you should create
}
}
}

        }
              runOnUiThread(new Runnable() {
                     public void run() {
                         adapter.clear();
                         for(int z=0;z<k;z++){

                             adapter.add(s[z]);
                         }
                         adapter.notifyDataSetChanged();



                    }
                });


          }


          }



          }}).start();




}



private OnItemClickListener mMessageClickedHandler = new 
         OnItemClickListener() {
             public void onItemClick(AdapterView<?> parent, View v, int position, long id){
                 infra=false;
                 String s=d[position];
                 finish();
                 Intent k=new Intent(InfrapagesActivity.this,InfrapagesActivity.class);
                 startActivity(k);
                 Intent i=new Intent(this,nextactivity.class);
                 i.putExtra("hash",s);
                 startActivity(i);


             }
};
             }

next activity

public class nextactivity extends ListActivity{
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         type = getIntent().getExtras().get("hash").toString();....

you can search using the string "type" and populate the list...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top