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 particular positions in grid view. how do i do that. i used convertView.setclickable(false) for particular position in getView which is giving null pointer exception. How do i do that?? here s my code.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
textView = new TextView(context);
textView.setLayoutParams(new GridView.LayoutParams(35, 35));
} else {
textView = (TextView) convertView;
}
textView.setTextSize(10);
day_color = list.get(position).split("-");
textView.setText(day_color[0]);
if (day_color[1].equals("GREY")) {
textView.setTextColor(Color.LTGRAY);
//greyvalues.get(position)CalendarEvents
convertView.setClickable(false);
}
if (day_color[1].equals("BLACK")) {
textView.setTextColor(Color.BLACK);
}
if ((day_color[1].equals("BLUE"))) {
textView.setTextColor(Color.RED);
}
setColor = Color.TRANSPARENT;
if (position >= startPos && position <= endPos
&& selectdayselected != true) {
setColor = Color.DKGRAY;
}
if (startPos == position && selectdayselected == true)
setColor = Color.DKGRAY;
textView.setBackgroundColor(setColor);
return textView;
}
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:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
if (position == 0){
isEnabled(position)
}
...
}
@Override
public boolean isEnabled(int position){
if(position == 0)
return false;
else
return true;
}
@Override
public boolean areAllItemsEnabled(){
return true;
}
Code adapted to your needs, I hope its work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With