我有一个AutoCompleteTextView,并为其设置了onItemSelectedListener,但它不起作用。
你有任何想法是什么问题吗? 这是我的Activity代码,如果需要,我还可以提供main.xml文件。
package com.chidem;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class ChidemActivity extends Activity implements OnItemSelectedListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String hop[]=new String[]{
"Karen","Mika","Gevor"
};
AutoCompleteTextView searchHotels = (AutoCompleteTextView) findViewById(R.id.autoSearch);
searchHotels.setOnItemSelectedListener(this);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>( this, R.layout.list_item, hop);
searchHotels.setAdapter(adapter1);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Log.d("autocomplete", "itemselected");
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}