Android:为什么onTouchListener()会打开多个警报对话框?
我想在单击微调器时打开一个包含自动完成文本视图的警报对话框。这是密码Android:为什么onTouchListener()会打开多个警报对话框?,android,android-spinner,ontouchlistener,Android,Android Spinner,Ontouchlistener,我想在单击微调器时打开一个包含自动完成文本视图的警报对话框。这是密码 resNonRes = (Spinner)activity.findViewById(componentNameIdMap.get("SPINNER")); resNonRes.setOnTouchListener(touch); OnTouchListener touch = new OnTouchListener(){ @Override public boolean onTouch(View v, Mo
resNonRes = (Spinner)activity.findViewById(componentNameIdMap.get("SPINNER"));
resNonRes.setOnTouchListener(touch);
OnTouchListener touch = new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
final AutoCompleteTextView av = new AutoCompleteTextView(activity);
av.setAdapter((ArrayAdapter)resNonRes.getAdapter());
AlertDialog.Builder builderSingle = new AlertDialog.Builder(activity);
builderSingle.setTitle("Exception");
builderSingle.setView(av);
builderSingle.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String avv = av.getText().toString();
ArrayAdapter myAdap = (ArrayAdapter) resNonRes.getAdapter(); //cast to an ArrayAdapter
int spinnerPosition = myAdap.getPosition(avv); //set the default according to value
resNonRes.setSelection(spinnerPosition);
}
});
builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
builderSingle.show();
return false;
}
};
但它会打开多个警报对话框
我不能使用onclick侦听器,因为微调器不支持项目单击事件,也不能使用onItemSelectedSpinner,因为我的项目中存在约束,因为我将其用作所有微调器的常规设置。
请建议…因为您正在为所有触控事件(向上、向下、移动等)执行此操作。您应该只在向上执行此操作。因为它在多个事件(如“向下、向上,…)中启动,所以您应该检查您的欲望事件,并在其中写入您自己的函数。感谢您的回复。是的,很管用。