How can I disable the OnItemClick() once a List item has been clicked? I am t开发者_开发问答rying to display a list of items in a grid view. Once the user clicks on one item, it must not be possible for him to click again on the same item and trigger an onClick action a second time.
I think you have to play a trick. What you need to do is inside onItemClickListener you maintain the list of items that are clicked. Use position argument of that.
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
}
Now when item gets clicked, you scan whether this item is pressed before, if its cicked before then do nothing(you can do your own task when its clicked again) else if its clicked for the first time, then you have to do two tasks : 1. Mark its entry in clicked items 2. Do the task you want.
U need to maintain some clickcount
to do this i think. cos whenever u click on it.. It will be calling onItemClick()
else u can make the clickable
false for the position where it got clicked..
Edit: I misunderstood the question. The following will block the responsiveness to the whole list, not the particular item. Kartik's response is much better.
list.setClickable(false) should do the trick
http://developer.android.com/reference/android/view/View.html#setClickable(boolean)
Thanks all. Yeah, Kartik's idea will work fine. I have solved it in the following way:
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
if(position==0){
if(click1==0){
point+=125;
Toast.makeText(Rewards.this, "125 points added", Toast.LENGTH_SHORT).show();
click1++;
}
else{
isEnabled(position);
}
}
public boolean isEnabled(int position) {
boolean val=true;
if(position==0){
val=false;
}
return val;
}
You can use the same logic for all the positions and it works fine.
精彩评论