我正在创建一个活动,其中有 textview/autocompletetextview、listview 和一个按钮。我的自动完成文本视图运行良好,但我想将我在文本视图中输入的内容索引到列表视图,当它突出显示时,我会单击按钮并转到相应的活动。
到目前为止,这是我所做的:
String[] classes = {
"Acornsquash",
"Almonds",
"Apples", }
private ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature( Window.FEATURE_LEFT_ICON );
setContentView(R.layout.nutritional_list);
setFeatureDrawableResource( Window.FEATURE_LEFT_ICON, R.drawable.nutrition32 );
//ArrayAdapter<String> adapter = new ArrayAdapter<String>( this,
// android.R.layout.simple_dropdown_item_1line, classes );
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_list_item, classes );
AutoCompleteTextView tv = ( AutoCompleteTextView ) findViewById ( R.id.txtSearcEngine );
tv.setThreshold( 3 );
tv.setAdapter( adapter );
tv.setTextColor( Color.BLACK );
lv = ( ListView ) findViewById(R.id.lvListSearch);
lv.setAdapter(new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, classes ) );
lv.setOnItemClickListener( this );
public void onItemClick( AdapterView<?> parent, View v, int position, long id ) {
lv.setSelection(position);
switch( position )
{
case 0:
Intent acorn = new Intent( Nutritional_List.this, AcornSquash.class );
startActivity( acorn );
break;
case 1:
Intent almonds = new Intent( Nutritional_List.this, Almonds.class );
startActivity( almonds );
break;
我的问题是,我不知道如何将建议从 autocompletetextview 索引到 listview。有什么帮助吗?谢谢。