有时listview糟糕的加载Android

时间:2015-03-17 14:48:09

标签: android listview adapter

我正在预订保龄球,我的列表视图中有特定的问题 我在这里做了自定义适配器:

public ReservationAdapter(Context context, List<Reservation> items, int year, int month, int day) {
        this.context = context;
        this.listReservations = items;
        this.year = year;
        this.month = month;
        this.day = day;
}

/*private view holder class*/
private class ViewHolder {
    TextView time;
    Button reserve;
}

public View getView(int position, View convertView, ViewGroup parent) {

    final ViewHolder holder;

    LayoutInflater mInflater = (LayoutInflater)
            context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.rowitem_reservation_layout, null);

        holder = new ViewHolder();
        holder.time = (TextView) convertView.findViewById(R.id.reserve_textview);
        holder.reserve = (Button) convertView.findViewById(R.id.reserve_button);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    reservation = (Reservation) getItem(position);

    Calendar calendar = Calendar.getInstance();
    calendar.set(year,month,day);
    Calendar calendarToday = Calendar.getInstance();

    holder.time.setText(reservation.getStartHour() + ":00 - " + reservation.getEndHour() + ":00");
    holder.reserve.setTag(reservation.getStartHour() + ":00 - " + reservation.getEndHour() + ":00");

    if (reservation.getStartHour() <= calendar.get(Calendar.HOUR_OF_DAY) && calendar.equals(calendarToday)) {
        holder.reserve.setBackgroundResource(R.drawable.closed_button);
        holder.reserve.setClickable(false);
        holder.reserve.setFocusable(false);
        holder.reserve.setText("Closed");
    } else {
        if (reservation.isReserved()) {
            holder.reserve.setBackgroundResource(R.drawable.reserved_button);
            holder.reserve.setClickable(false);
            holder.reserve.setFocusable(false);
            holder.reserve.setText("Reserved");
        } else {
            if (reservation.isSelected()) {
                holder.reserve.setBackgroundResource(R.drawable.selected_button);
                holder.reserve.setClickable(true);
                holder.reserve.setFocusable(true);
                holder.reserve.setText("Selected");
            }
            else{
                holder.reserve.setBackgroundResource(R.drawable.nonreserved_button);
                holder.reserve.setClickable(true);
                holder.reserve.setFocusable(true);
                holder.reserve.setText("Free");
            }
        }
    }

    holder.reserve.setId(position);

    return convertView;
}

它扩展了BaseAdapter我实现的方法getCount,getItem和getItemId只是不要粘贴它们。

问题:有时候有时某些必须关闭的行不会被关闭 当我向下和向上滚动或创建列表视图的活动时会出现问题

请帮我解决这个问题

0 个答案:

没有答案