我有一个扩展ListFragment的片段类。 onListItemClick()
如下 -
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
MyAdapter.MergedData item = adapter.getItem(position);
Intent intent = MyActivity.createIntent(mActivity, item);
startActivity(mActivity, intent);
}
要求是我需要禁用快速单击列表项。我怎样才能实现它?
答案 0 :(得分:0)
执行以下操作......
/**
* used to prevent the double click on some view
*
* @param view a view whick is required prevention.
*/
public static void preventDoubleClick(final View view) {
view.setEnabled(false);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
view.setEnabled(true);
}
}, 2000); //set this based on your requirement
}
在
上调用此方法@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
//used to prevent the rapid clicks....
preventDoubleClick(v);
MyAdapter.MergedData item = adapter.getItem(position);
Intent intent = MyActivity.createIntent(mActivity, item);
startActivity(mActivity, intent);
}
你完成了!
答案 1 :(得分:0)
我猜你可以禁用视图一段时间,使用此功能: -
public static void preventDoubleClick(final View v) {
v.setEnabled(false);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
v.setEnabled(true);
}
}, 1000); // Will disable view for 1 sec.
}