我有一个autocompleteTextview,我在其中加载一个字符串数组..所以我可以通过键入firstletter来搜索数据。现在我需要加载一个列表来选择自动完成textview中的每个项目..如何它可能吗?
这是我的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);
提前致谢
答案 0 :(得分:1)
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);
}
};
}
下一个活动
public class nextactivity extends ListActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
type = getIntent().getExtras().get("hash").toString();....
您可以使用字符串“type”进行搜索并填充列表...