问题
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