如何在Android中的网格视图中禁用特定位置的项目点击

前端之家收集整理的这篇文章主要介绍了如何在Android中的网格视图中禁用特定位置的项目点击前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用网格视图,其中我正在为每个单元格使用文本视图.当我点击网格单元格时,我正在使用onitemclick执行一些操作.我想禁用项目点击网格视图中的特定位置.我怎么做.我使用convertView.setclickable(false)在getView中的特定位置,它提供空指针异常.我怎么做??这是我的代码
  1. @Override
  2. public View getView(int position,View convertView,ViewGroup parent) {
  3. if (convertView == null) {
  4. textView = new TextView(context);
  5. textView.setLayoutParams(new GridView.LayoutParams(35,35));
  6. } else {
  7. textView = (TextView) convertView;
  8. }
  9.  
  10. textView.setTextSize(10);
  11. day_color = list.get(position).split("-");
  12. textView.setText(day_color[0]);
  13.  
  14. if (day_color[1].equals("GREY")) {
  15. textView.setTextColor(Color.LTGRAY);
  16. //greyvalues.get(position)CalendarEvents
  17. convertView.setClickable(false);
  18.  
  19. }
  20. if (day_color[1].equals("BLACK")) {
  21. textView.setTextColor(Color.BLACK);
  22. }
  23. if ((day_color[1].equals("BLUE"))) {
  24. textView.setTextColor(Color.RED);
  25. }
  26.  
  27. setColor = Color.TRANSPARENT;
  28. if (position >= startPos && position <= endPos
  29. && selectdayselected != true) {
  30. setColor = Color.DKGRAY;
  31. }
  32. if (startPos == position && selectdayselected == true)
  33. setColor = Color.DKGRAY;
  34. textView.setBackgroundColor(setColor);
  35.  
  36.  
  37. return textView;
  38. }

解决方法

在你的适配器覆盖
  1. @Override
  2. public boolean areAllItemsEnabled() {
  3. return false;
  4. }

并实施

  1. @Override
  2. public boolean isEnabled(int position) {
  3. // Return true for clickable,false for not
  4. return false;
  5. }

猜你在找的Android相关文章