我正在使用网格视图,其中我正在为每个单元格使用文本视图.当我点击网格单元格时,我正在使用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;
- }
解决方法
在你的适配器覆盖
- @Override
- public boolean areAllItemsEnabled() {
- return false;
- }
并实施
- @Override
- public boolean isEnabled(int position) {
- // Return true for clickable,false for not
- return false;
- }