这是我在Android及其点击事件中实现自动完成的代码。
AutoCompleteTextView StreetDataNew = (AutoCompleteTextView)findViewById(R.id.Street)
...........................
.........................
StreetDataNew
.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings({ "unused", "unchecked" })
@Override
public void onItemClick(AdapterView<?> arg0,
View arg1, int index, long id) {
}
});
请告诉我如何抓住自动完成项目是否滚动?
答案 0 :(得分:0)
您可以执行以下操作,以了解所选项目是否高于上一个选择项目或以下项目:
1st - 创建一个变量来存储最后选择的值:
private int lastIndex ;
2nd - 在AutoCompletetextView上设置OnItemClickListener,如下所示:
autoComplete.setOnItemClickListener(this);
3 - 实现你的onItemClick,如下所示:
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
if(lastIndex==position){
Toast.makeText(getApplicationContext(), "same positon ",
Toast.LENGTH_LONG).show();
}else if (position<lastIndex){
Toast.makeText(getApplicationContext(), "scroll up",
Toast.LENGTH_LONG).show();
}else if (position>lastIndex){
Toast.makeText(getApplicationContext(), "scroll down ",
Toast.LENGTH_LONG).show();
}
lastIndex=position;
}
请给我一些反馈
希望有所帮助。