how to disable item in gridview in android

老子叫甜甜 提交于 2019-12-11 01:55:22

问题


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-

        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int no,long lg) {
            // TODO Auto-generated method stub

            final AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
            id=no;

            final EditText input = new EditText(MainActivity.this);
            alert.setView(input);

            alert.setPositiveButton("Check", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

            String value = input.getText().toString();

              AlertDialog.Builder alert1 = new AlertDialog.Builder(MainActivity.this);

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

                              // here i want to disable item
            alert1.setPositiveButton("Correct", new DialogInterface.OnClickListener() { 
              public void onClick(DialogInterface dialog, int whichButton) {

                      }
                    });

              }
              else
              {

              }
            }
            });

            alert.show();
        }
    });

回答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.




回答2:


Try this,

   @Override
        public void onItemClick(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 4


      if (no==4){
// do nothing
}
else{
 final AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
            id=no;

            final EditText input = new EditText(MainActivity.this);
            alert.setView(input);

            alert.setPositiveButton("Check", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

            String value = input.getText().toString();

              AlertDialog.Builder alert1 = new AlertDialog.Builder(MainActivity.this);

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

                              // here i want to disable item
            alert1.setPositiveButton("Correct", new DialogInterface.OnClickListener() { 
              public void onClick(DialogInterface dialog, int whichButton) {

                      }
                    });

              }
              else
              {

              }
            }
            });

            alert.show();
        }
}





    });


来源:https://stackoverflow.com/questions/13697957/how-to-disable-item-in-gridview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!