2012-12-04 129 views
2

在我的gridview中有imageview.I想要禁用當前項目/圖像在android.config中的gridview中點擊我不能做到這一點。 這裏是一個代碼 -如何在gridview中禁用項目android

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

你做了什麼來禁用一個項目? – mango

+1

以及「禁用項目」是什麼意思? –

+0

第一次當我點擊任何item.then執行操作後,下一次該項目不應該被點擊/選擇 –

回答

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





    }); 
+0

得到空指針異常。我想只禁用選擇項目。即如果我點擊我的網格視圖的第一項,然後只有第一個圖像應該禁用 –

8

你需要一個定製的適配器。

覆蓋的方法

ListAdapter.isEnabled(int position) 

,並覆蓋ListAdapter.areAllitemsEnabled()返回false。

完全禁用點擊,以及在GridView的用戶界面中選擇圖形。

相關問題