添加布尔变量着陆和润色的适配器类如下似乎运作得相当好:
private class MyListAdapter extends ArrayAdapter<MyObject>{
...
//touch down + touch up with no other motion events in between = click
boolean touchDown = false;
boolean touchUp = false;
private int iHostViewID;
...
public MyListAdapter(Context context,int viewResourceId, List<MyObject> objects) {
super(context, textViewResourceId, objects);
iHostViewID = viewResourceId;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
View itemView = convertView;
//iff we cannot re-use a view
if(itemView == null){
LayoutInflater inflater = (
(LayoutInflater)hContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
itemView = inflater.inflate(iHostViewID, null);
}
final View hItemView = itemView;
final int hPosition = pos;
...
final HorizontalScrollView textDataSV =
(HorizontalScrollView)itemView.findViewById(R.id.widget_hsv);
textDataSV.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
touchDown = true;
}
else if(event.getAction() == MotionEvent.ACTION_UP){
touchUp = true;
}
else{
touchDown = false;
touchUp = false;
}
if(touchDown && touchUp){
//click
//mMyListView is the reference to the list view
//instantiated in the view controller class responsible
//for setting this adapter class as the list view's adapter
mMyListView.performItemClick(hItemView, hPosition,
hItemView.getId());
}
return false;
}
});
}
}
它远非完美,但也应根据大多数标准使用情况
来源
2014-07-10 21:46:27
CCJ
工作,请使用try catch blog surroung listview点击事件并在日志中打印错误,并在这里发布我们的错误,以便我们能够快速地知道发生了什么问题。 – Aamirkhan
我没有任何错误......问题在于如何以这种方式设置视图的行为。 – startupsmith
好的,你可以使用自定义adatper来发布你的xml文件吗? – Aamirkhan