Có các trình nghe nhấp chuột khác nhau trong AutoCompleteTextView.
Cách đầu tiên là trong bố cục xml, bạn có thể xác định thuộc tính onCLick, với hàm bạn muốn được gọi, trong ví dụ bên dưới, được nhấp.
<AutoCompleteTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="clicked" />
Sau đó, trong hoạt động của bạn, bạn xác định chức năng được nhấp.
public void clicked(View v) {
// on click do ..
}
Hoặc bạn có thể đặt nó trực tiếp trong mã của bạn:
ACTV.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Nếu bạn muốn thiết lập người nghe nhấp chuột khi người dùng nhấp vào một mục trong danh sách thả xuống có một phương pháp khác, các setOnItemClickListener.
ACTV.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
//... your stuff
}
})
Và bạn có một lựa chọn cuối cùng, để thiết lập các listener nhấp chuột khi người dùng thực sự chọn một mục trong danh sách thả xuống bằng setOnItemSelectedListener.
ACTV.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected (AdapterView<?> parent, View view, int position, long id) {
//... your stuff
}
@Override
public void onNothingSelected (AdapterView<?> parent) {
//... your stuff
}
})
Tài liệu tham khảo:
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
Chúc may mắn!
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html#setOnItemClickListener(android.widget.AdapterView.OnItemClickListener) –