【发布时间】:2023-04-06 01:58:01
【问题描述】:
我正在使用网格视图,其中我为每个单元格使用文本视图。单击网格单元格时,我正在使用 onitemclick 执行某些操作。我想在网格视图中禁用特定位置的项目单击。我怎么做。我将 convertView.setclickable(false) 用于 getView 中的特定位置,这给出了空指针异常。我怎么做??这是我的代码。
@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;
}
【问题讨论】:
标签: android