How To Disable Item Click For Particular Positions In Grid View In Android
i am using a grid view in which i am using a text view for each cell. i am using onitemclick to perform some action when clicked on grid cell. i want to disable on item click for
Solution 1:
In your adapter override
@OverridepublicbooleanareAllItemsEnabled() {
returnfalse;
}
and implement
@OverridepublicbooleanisEnabled(int position) {
// Return true for clickable, false for notreturnfalse;
}
Solution 2:
Solution 3:
You need to set it on textView
. There may not be a convert view, which will cause an NPE when you call setClickable
on it.
Solution 4:
Like example your code about the condition:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
if (day_color[1].equals("GREY")) {
textView.setTextColor(Color.LTGRAY);
//greyvalues.get(position)CalendarEvents
convertView.setClickable(false);
...
}
your condition like example may be:
if (position == 0){
isEnabled(position)
}
the code functionally:
@OverridepublicViewgetView(int position, View convertView, ViewGroup parent) {
...
if (position == 0){
isEnabled(position)
}
...
}
@OverridepublicbooleanisEnabled(int position){
if(position == 0)
returnfalse;
elsereturntrue;
}
@OverridepublicbooleanareAllItemsEnabled(){
returntrue;
}
Code adapted to your needs, I hope its work for you.
Solution 5:
I have searched through this list and could not find any answer that worked for me. Apparently, I tried the following code and it worked.
I have a textview within the grid and the text view is disabled, however the onClick method is for the Grid (as we need to capture the position of the click) and it is always enabled. So, I decided to check whether the child element of the grid is enabled or disabled like this...
grid.setOnItemClickListener(newAdapterView.OnItemClickListener() {
@OverridepublicvoidonItemClick(AdapterView<?> view, View cell, int position, long id)
{
if (grid.getChildAt(position).isEnabled()) //do whatever you want
}
});
Post a Comment for "How To Disable Item Click For Particular Positions In Grid View In Android"