gridView.setOnItemClickListener ( new AdapterView.OnItemClickListener () {
@Override
public void onItemClick ( AdapterView< ? > parent, View view, int position, long id ) {
ViewFlipper viewFlipper= ( ViewFlipper )view.findViewById ( R.id.viewFlipper );
view.setEnabled (false);
view.setClickable ( false );
choose ( viewFlipper, position );
}
} );
想要禁用已点击的项目,在我设置之前无法再次点击,如果可以再次点击。我使用上面的方法,但项目仍然可以点击。希望有人可以帮助我,以便在我点击它一次后它会被禁用。
解决方案: 感谢Androider,稍微修改然后得到我想要的东西。 在适配器上创建一个arraylist,并在表上添加true。
// put inside the Adapter
ArrayList<Boolean> itemClickable =new ArrayList<Boolean> ();
@Override
public boolean isEnabled ( int position ) {
return itemClickable.get ( position );
}
public void setItemClickable(int position,Boolean typeValue){
itemClickable.add (position,typeValue);
}
//put inside OnCreate /Constructor
for(int j=0;j<picturePath.length;j++){
itemClickable.add ( true );
}
答案 0 :(得分:3)
在你的适配器中执行以下操作:
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int position) {
// according to position return here true or false to enable or disable respectively
return false;
}
进行更多检查:http://developer.android.com/reference/android/widget/BaseAdapter.html#isEnabled(int) http://developer.android.com/reference/android/widget/ListAdapter.html#areAllItemsEnabled()
答案 1 :(得分:1)
// put inside the Adapter
ArrayList<Boolean> itemClickable =new ArrayList<Boolean> ();
@Override
public boolean isEnabled ( int position ) {
return itemClickable.get ( position );
}
public void setItemClickable(int position,Boolean typeValue){
itemClickable.add (position,typeValue);
}
//put inside OnCreate /Constructor
for(int j=0;j<picturePath.length;j++){
itemClickable.add ( true );
}
// you can disable grid item using
adapter.setItemClickable(position,false);
enter code here
//// add grid item click listener////////
gridView.setOnItemClickListener ( new AdapterView.OnItemClickListener () {
@Override
public void onItemClick ( AdapterView< ? > parent, View view, int position, long id )
boolean isEnable=adapter.isEnabled(position)
if(isEnable){
// write your action here
}
}
} );