网格视图中的文本视图在网格视图滚动中消失

时间:2014-05-30 08:41:45

标签: java android gridview

我遇到了机器人网格视图的问题。当我滚动时,一些文本视图消失。我有一个条件语句,它检查数据库中的值并基于此隐藏文本视图。但该条件语句仅适用于符合条件的网格视图。但是,滚动时所有视图似乎都会发生变化。

这是我的自定义数组适配器(我还添加了一个图像以显示我的意思):

![public class ArrayAdapterHandler extends ArrayAdapter<Day> {

    public Context context;
    int layoutResourceId;
    ArrayList<Day> days = new ArrayList<Day>();

    public ArrayAdapterHandler(Context context, int dayId,
            ArrayList<Day> days) {
        super(context, dayId, days);
        this.layoutResourceId = dayId;
        this.context = context;
        this.days = days;
    }

    /*private view holder class*/
    private class ViewHolder {
        TextView day_text;
        TextView situps_text;
        TextView crunches_text;
        TextView legRaises_text;
        TextView plank_text;
    }

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

        ViewHolder holder = null;
        Day day = days.get(position);

        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.day_row, null);
            if (position % 2 == 0) {
                convertView.setBackgroundColor(0x30BFFF1E);
            } else {
                convertView.setBackgroundColor(0x30CCCCCC);
            }
            holder = new ViewHolder();
            holder.day_text = (TextView) convertView.findViewById(R.id.day_text);
            holder.situps_text = (TextView) convertView.findViewById(R.id.situps_text);
            holder.crunches_text = (TextView) convertView.findViewById(R.id.crunches_text);
            holder.legRaises_text = (TextView) convertView.findViewById(R.id.legRaise_text);
            holder.plank_text = (TextView) convertView.findViewById(R.id.plank_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.day_text.setText(String.valueOf(day.getDay()));

        if (day.isCompleted() == 1 || day.isRestDay() == 1) {
            // Hide all the activity values which are 0 anyway.
            holder.situps_text.setVisibility(4);
            holder.legRaises_text.setVisibility(4);
            holder.plank_text.setVisibility(4);
        }
        if (day.isRestDay() == 1) {
            holder.crunches_text.setText("REST DAY");
        } else if(day.isCompleted() == 1) {
            holder.crunches_text.setText("COMPLETED!");
        } else {
            holder.situps_text.setText(String.valueOf(day.getSitups()) + " situps");
            holder.crunches_text.setText(String.valueOf(day.getCrunches()) + " crunches");
            holder.legRaises_text.setText(String.valueOf(day.getLegRaises()) + " leg raises");
            holder.plank_text.setText(String.valueOf(day.getPlanks()) + "sec planks");
        }

        return convertView;
    }

}

![滚动问题图片]:http://i.stack.imgur.com/zB3uL.png

三江源。

0 个答案:

没有答案