如何禁用项目点击在网格视图在android的特定位置上网格、视图、位置、项目

2023-09-05 09:23:37 作者:再牛逼的男人也是女人生的

我使用在我使用的每一个细胞的文本视图网格视图。我使用onitemclick在网格单元点击时执行一些动作。我想禁用项目点击在网格视图中特定位置上。我怎么做。我用convertView.setclickable(假)在getView这是给空指针异常特殊的位置。我怎么做??这里是我的code。

  @覆盖
公共查看getView(INT位置,查看convertView,ViewGroup中父){
  如果(convertView == NULL){
    TextView的=新的TextView(上下文);
    textView.setLayoutParams(新GridView.LayoutParams(35,35));
  } 其他 {
    TextView的=(的TextView)convertView;
  }

        textView.setTextSize(10);
        day_color = list.get(位置).split( - );
        textView.setText(day_color [0]);

        如果(day_color [1] .equals(灰色)){
            textView.setTextColor(Color.LTGRAY);
            //greyvalues​​.get(position)CalendarEvents
            convertView.setClickable(假);

        }
        如果(day_color [1] .equals(黑)){
            textView.setTextColor(Color.BLACK);
        }
        如果((day_color [1] .equals(蓝))){
            textView.setTextColor(Color.RED);
        }

        setColor = Color.TRANSPARENT;
        如果(位置> = startPos和放大器;&安培;位置< = endPos
                &功放;&安培; selectdayselected!= TRUE){
            setColor = Color.DKGRAY;
        }
        如果(startPos ==位置和放大器;&安培; selectdayselected ==真)
            setColor = Color.DKGRAY;
        textView.setBackgroundColor(setColor);


        返回的TextView;
    }
 

解决方案

在您的适配器覆盖

  @覆盖
公共布尔areAllItemsEnabled(){
    返回false;
}
 
pyrosim2019破解版

和实施

  @覆盖
公共布尔的IsEnabled(INT位置){
   //返回true的点击,虚假不
   返回false;
}
 

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;
    }

解决方案

In your adapter override

@Override
public boolean areAllItemsEnabled() {
    return false;
}

and implement

@Override
public boolean isEnabled(int position) {
   // Return true for clickable, false for not
   return false;
}