Reputation: 3703
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();
}
});
Upvotes: 2
Views: 4581
Reputation: 354
Override "isEnabled()" method inside the custom adapter as follows :
public class CustomAdapter extends BaseAdapter {
//other implemented methods
@Override
public boolean isEnabled(int position) {
return false;
}
}
Upvotes: 0
Reputation: 7834
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.
Upvotes: 8
Reputation: 6925
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();
}
}
});
Upvotes: 0