OnClickListener not working for first item in GridView

前端 未结 7 1538
一向
一向 2020-12-03 02:54

I have a problem with creating a GridView-based calendar. Here is the Grid:

\"GridView

This

7条回答
  •  时光取名叫无心
    2020-12-03 03:44

    Ok, I found the solution. The problem was these lines:

    ViewHolder holder;
    if (convertView == null)
    {
        holder = new ViewHolder();
        LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.calendar_day_gridcell, parent, false);
        holder.gridCell = (Button) convertView.findViewById(R.id.calendar_day_gridcell_button);
        holder.multiDayEvent = (EventLengthView) convertView.findViewById(R.id.eventLengthView);
        convertView.setTag(holder);
    }
    else {
        holder = (ViewHolder) convertView.getTag();
    }
    

    When putting instatiating the gridCell button there, somehow, it mixes up the click listener of the first position in the adapter. I ended up fixing it by just instatiating the holder in every pass, instead of getting it by tag (which is better for performance, but oh well). Thanks everyone for the help.

提交回复
热议问题