Skip to content Skip to sidebar Skip to footer

How To Disable Item In Gridview In Android

There is imageview in my gridview.I want to disable current item/image which is clicked in gridview of android.I am not able to do this.how to do this?? here is a code- @Ov

Solution 1:

You need a custom adapter.

Override the methods

ListAdapter.isEnabled(int position)

and override ListAdapter.areAllitemsEnabled() to return false.

Completely disables clicking, as well as selection graphics in the UI for GridView.

Solution 2:

Try this,

@OverridepublicvoidonItemClick(AdapterView<?> arg0, View v, int no,long lg) {
            // TODO Auto-generated method stub// check for item clicked  say you have to disable image at position 4if (no==4){
// do nothing
}
else{
 final AlertDialog.Builderalert=newAlertDialog.Builder(MainActivity.this);
            id=no;

            finalEditTextinput=newEditText(MainActivity.this);
            alert.setView(input);

            alert.setPositiveButton("Check", newDialogInterface.OnClickListener() {
            publicvoidonClick(DialogInterface dialog, int whichButton) {

            Stringvalue= input.getText().toString();

              AlertDialog.Builderalert1=newAlertDialog.Builder(MainActivity.this);

              if(value.equalsIgnoreCase(country[id])){

                              // here i want to disable item
            alert1.setPositiveButton("Correct", newDialogInterface.OnClickListener() { 
              publicvoidonClick(DialogInterface dialog, int whichButton) {

                      }
                    });

              }
              else
              {

              }
            }
            });

            alert.show();
        }
}





    });

Solution 3:

Override "isEnabled()" method inside the custom adapter as follows :

publicclassCustomAdapterextendsBaseAdapter {

    //other implemented methods@OverridepublicbooleanisEnabled(int position) {
        returnfalse;
    }
}

Post a Comment for "How To Disable Item In Gridview In Android"