我正在使用网格视图,其中我使用每个单元格的文本视图.我正在使用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;
}
Run Code Online (Sandbox Code Playgroud)
slu*_*und 40
在适配器覆盖中
@Override
public boolean areAllItemsEnabled() {
return false;
}
Run Code Online (Sandbox Code Playgroud)
并实施
@Override
public boolean isEnabled(int position) {
// Return true for clickable, false for not
return false;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12220 次 |
最近记录: |