Android ListView无法正确重绘

时间:2013-05-21 05:18:28

标签: android android-listview scroll redraw

我有一个ListFragment的自定义行。 问题是当我滚动项目时,基础项目不会消失。 它们仍然可见,我找不到解决这个问题的方法。

Loader通过ArrayAdapter

从数据库加载项目
         @Override
      public View getView(int position, View row, ViewGroup parent)
      {

        ViewHolder holder = null;

        if(row == null)
        {
          row = mInflater.inflate(R.layout.list_item_expense, null, false);
          holder = new ViewHolder();
          holder.layout = (CheckableLinearLayout)row.findViewById(R.id.mylinearlayout);
          holder.id = ((TextView)row.findViewById(R.id.id));
          holder.category = ((TextView)row.findViewById(R.id.category));
          holder.date = ((TextView)row.findViewById(R.id.date));
          holder.note = ((TextView)row.findViewById(R.id.note));

          row.setTag(holder);
          // We will watch for the checked state and remember it
          holder.layout.setCheckChangeListener(ExpenseListAdapter.this);
        }
        else
        {
          holder = (ViewHolder)row.getTag();
        }

    Expense item = getItem(position);
    holder.id.setText(Integer.toString(item.getId()));
    holder.category.setText(Integer.toString(item.getCategory()));
    holder.note.setText(item.getNote());
    holder.date.setText(item.getDateDisplay());

    holder.layout.setTag(R.id.mylinearlayout, position);
    // Restore the checked state properly
    final ListView lv = (ListView)parent;
    holder.layout.setChecked(lv.isItemChecked(position));

    return row;
  }

行布局是:

    <?xml version="1.0" encoding="utf-8"?>
<com.nutelar.expensemaster.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mylinearlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/id"
        android:layout_width="48dip"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:focusable="false"
        android:textColor="@color/TextColor"
        android:textIsSelectable="false" />

    <TextView
        android:id="@+id/category"
        android:layout_width="48dip"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:focusable="false"
        android:textColor="@color/HeaderColor"
        android:textIsSelectable="false" />

    <TextView
        android:id="@+id/date"
        android:layout_width="248dip"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:focusable="false"
        android:textIsSelectable="false" />

    <TextView
        android:id="@+id/note"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1.0"
        android:clickable="false"
        android:focusable="false"
        android:textIsSelectable="false" />

    <com.nutelar.expensemaster.InertCheckBox
        android:id="@+id/itemCheckBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dp"
        android:focusable="false" />

</com.nutelar.expensemaster.CheckableLinearLayout>

当我向上滚动时,先前的行保持“基础”,而新数据在“前景”中加载。行似乎向下移动。

0 个答案:

没有答案