2

我的gridview中有imageview。我想禁用在android的gridview中单击的当前项目/图像。我无法做到这一点。如何做到这一点?这是一个代码-

        @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();
        }
    });
4

3 回答 3

8

您需要一个自定义适配器。

覆盖方法

ListAdapter.isEnabled(int position)

并覆盖 ListAdapter.areAllitemsEnabled() 以返回 false。

在 GridView 的 UI 中完全禁用单击以及选择图形。

于 2012-12-04T08:58:45.067 回答
0

尝试这个,

   @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();
        }
}





    });
于 2012-12-04T07:28:09.503 回答
0

在自定义适配器中覆盖“isEnabled()”方法,如下所示:

public class CustomAdapter extends BaseAdapter {

    //other implemented methods

    @Override
    public boolean isEnabled(int position) {
        return false;
    }
}
于 2022-01-12T06:30:15.240 回答