我需要帮助... :-) 我的 ListView 有一个自定义适配器。这些项目是 TextViews。我希望能够处理每个 TextView 上的 onSingleTap、onFling 和所有其他事件。但只有 onDown 事件有效!其他都不要!我不明白为什么。在我的其他活动中,TextViews 不是 ListView 的一部分,一切正常......
这就是我所拥有的:
public class ListViewAdapter extends BaseAdapter{
...
private GestureDetector txtProductGD;
private View.OnTouchListener txtProductGL;
...
public ListViewAdapter(Context context, ArrayList<Product> products) {
...
txtProductGL = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
txtProductGD = new GestureDetector(new txtProductGestureDetector((TextView) v));
return txtProductGD.onTouchEvent(event);
}
};
...
}
public View getView(int position, View convertView, ViewGroup parent) {
...
view = inflater.inflate(R.layout.listview_item, null);
TextView textView = (TextView) view.findViewById(R.id.txtProduct);
textView.setOnTouchListener(txtProductGL);
...
}
private class txtProductGestureDetector extends SimpleOnGestureListener {
private TextView textView;
public txtProductGestureDetector(TextView textView) {
this.textView = textView;
}
public boolean onDown (MotionEvent e) {
textView.setText("onDown..."); // IT WORKS!
return false;
}
public boolean onSingleTapConfirmed (MotionEvent e) {
textView.setText("onSingleTapConfirmed..."); // IT DOESN'T WORK!
return false;
}
// ALL OTHER METHODS ARE ALSO DON'T WORK!..
}
}