我有三个AutoCompleteTextView并设置onItemClickListener,请你帮我知道哪个AutoCompleteTextView被点击了
false
答案 0 :(得分:3)
使用View
比较视图ID的onItemClick
参数进行检查。如下所示
if(view.getId() == R.id.editTextUserNamecheck){
}else if(view.getId() == R.id.editTextPhoneNoNew){
}else if(view.getId() == R.id.searchProduct){
}
在public void onItemClick(AdapterView<?> parent, View view, int position, long id)
答案 1 :(得分:2)
,您可以识别Adapter AdapterView父级,这样您就可以首先识别父适配器。
如下所示
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (parent.getAdapter().getClass().equals(ProductAutoCmplt .class)) {
//do your stuff
}
else if(parent.getAdapter().getClass().equals(CustomPhoneArrayAdapterAutoCmplt .class)){
//do your stuff
}else if(parent.getAdapter().getClass().equals(CustomArrayAdapterAutoCmplt.class)){
//do your stuff
}
}
答案 2 :(得分:0)
使用匿名内部类,我们可以这样做:
txtUserName.setOnItemClickListener((new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// do your stuff;
}
});
txtContactNo.setOnItemClickListener((new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// do your stuff;
}
});
txtSearchProduct.setOnItemClickListener((new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// do your stuff;
}
});