CursorAdapter bindView为我提供了所有行的唯一视图

时间:2014-04-09 08:24:11

标签: android android-cursoradapter

CursorAdapter.bindView为我提供了所有行的单一视图。

在我的列表的第一个显示中,我遇到了在imageView中加载的图像的问题。 有些图像没有加载到好行中。 我的调查指出bindView为所有行传递了相同的imageView。所以我的asynTask会将图像加载到错误的行中。

public class MyCursorAdapter extends CursorAdapter {

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        return vi.inflate(R.layout.cursor_adapter_item, parent, false);
    }


    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        ImageView imageView = (ImageView) view.findViewById(R.id.cursor_adapter_item_image);
        d("bindView.cursor.getPosition() : " + cursor.getPosition());
        d("bindView imageView : " + imageView.toString());

        // logic to create/get/set the (remote) image. use local drawable or asyntask and a ref of imageview to load the image.
    }

列表的第一个油漆/展示的logcat摘录。请注意,所有imageView都获得了相同的参考。

04-09 10:58:57.520 E/TESTING (10211): MyCursorAdapter : notifyDataSetChanged
04-09 10:58:57.532 E/TESTING (10211): [MyCursorAdapter]newView.cursor.getPosition() : 0
04-09 10:58:57.532 E/TESTING (10211): [MyCursorAdapter]newView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.536 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 0
04-09 10:58:57.536 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.536 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8
04-09 10:58:57.551 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 1
04-09 10:58:57.551 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.551 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8
04-09 10:58:57.614 D/dalvikvm(10211): GC_FOR_ALLOC freed 11059K, 58% free 10701K/25415K, paused 58ms, total 59ms
04-09 10:58:57.614 W/SQLiteConnectionPool(10211): A SQLiteConnection object for database leaked [....]
04-09 10:58:57.684 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 2
04-09 10:58:57.684 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.684 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8
04-09 10:58:57.762 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 3
04-09 10:58:57.762 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.762 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8
04-09 10:58:57.766 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 4
04-09 10:58:57.766 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.766 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8
04-09 10:58:57.770 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 5
04-09 10:58:57.770 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.770 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8
04-09 10:58:57.778 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 6
04-09 10:58:57.778 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.778 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8
04-09 10:58:57.786 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 0
04-09 10:58:57.786 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 10:58:57.786 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8
04-09 10:58:57.797 E/TESTING (10211): [MyCursorAdapter]newView.cursor.getPosition() : 1
04-09 10:58:57.797 E/TESTING (10211): [MyCursorAdapter]newView view : android.widget.LinearLayout@422778d0
04-09 10:58:57.797 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 1
04-09 10:58:57.797 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@422778d0
04-09 10:58:57.797 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@41dce368
04-09 10:58:57.844 D/dalvikvm(10211): GC_FOR_ALLOC freed 928K, 55% free 11681K/25415K, paused 39ms, total 40ms
04-09 10:58:57.914 E/TESTING (10211): [MyCursorAdapter]newView.cursor.getPosition() : 2
04-09 10:58:57.914 E/TESTING (10211): [MyCursorAdapter]newView view : android.widget.LinearLayout@4203edb8
04-09 10:58:57.914 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 2
04-09 10:58:57.914 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@4203edb8
04-09 10:58:57.914 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@42012a50
04-09 10:58:57.926 E/TESTING (10211): [MyCursorAdapter]newView.cursor.getPosition() : 3
04-09 10:58:57.926 E/TESTING (10211): [MyCursorAdapter]newView view : android.widget.LinearLayout@423076e8
04-09 10:58:57.926 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 3
04-09 10:58:57.930 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@423076e8
04-09 10:58:57.930 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4232e5d8
04-09 10:58:57.942 E/TESTING (10211): [MyCursorAdapter]newView.cursor.getPosition() : 4
04-09 10:58:57.942 E/TESTING (10211): [MyCursorAdapter]newView view : android.widget.LinearLayout@423fd400
04-09 10:58:57.942 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 4
04-09 10:58:57.942 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@423fd400
04-09 10:58:57.942 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4234d8b0
04-09 10:58:57.953 E/TESTING (10211): [MyCursorAdapter]newView.cursor.getPosition() : 5
04-09 10:58:57.953 E/TESTING (10211): [MyCursorAdapter]newView view : android.widget.LinearLayout@42335f50
04-09 10:58:57.957 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 5
04-09 10:58:57.957 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42335f50
04-09 10:58:57.957 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423589b8
04-09 10:58:57.969 E/TESTING (10211): [MyCursorAdapter]newView.cursor.getPosition() : 6
04-09 10:58:57.969 E/TESTING (10211): [MyCursorAdapter]newView view : android.widget.LinearLayout@422dd560
04-09 10:58:57.973 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 6
04-09 10:58:57.973 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@422dd560
04-09 10:58:57.973 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423d9d58
04-09 10:58:58.168 E/DatabaseUtils( 6622): Writing exception to parcel
04-09 10:58:58.168 E/DatabaseUtils( 6622): java.lang.IllegalArgumentException: Invalid column orientation [...]
04-09 10:58:58.496 E/TESTING (10211): [MyCursorAdapter]newView.cursor.getPosition() : 0
04-09 10:58:58.496 E/TESTING (10211): [MyCursorAdapter]newView view : android.widget.LinearLayout@42270aa8
04-09 10:58:58.496 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 0
04-09 10:58:58.508 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42270aa8
04-09 10:58:58.508 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4236e480
04-09 10:58:58.512 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 1
04-09 10:58:58.512 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42270aa8
04-09 10:58:58.516 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4236e480
04-09 10:58:58.602 D/dalvikvm(10211): GC_FOR_ALLOC freed 2089K, 53% free 11981K/25415K, paused 73ms, total 79ms
04-09 10:58:58.700 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 2
04-09 10:58:58.700 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42270aa8
04-09 10:58:58.700 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4236e480
04-09 10:58:58.703 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 3
04-09 10:58:58.703 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42270aa8
04-09 10:58:58.703 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4236e480
04-09 10:58:58.711 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 4
04-09 10:58:58.711 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42270aa8
04-09 10:58:58.711 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4236e480
04-09 10:58:58.715 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 5
04-09 10:58:58.715 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42270aa8
04-09 10:58:58.715 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4236e480
04-09 10:58:58.719 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 6
04-09 10:58:58.719 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42270aa8
04-09 10:58:58.723 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4236e480
第一次涂漆后

滚动后的logcat提取向下滚动一个项目,然后向上滚动一个项目。请注意,imageView得到了不同的参考,并且图像显示在好行上。

04-09 11:05:10.192 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 7
04-09 11:05:10.192 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@42270aa8
04-09 11:05:10.192 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@4236e480
04-09 11:05:10.657 E/TESTING (10211): [MyCursorAdapter]bindView.cursor.getPosition() : 0
04-09 11:05:10.657 E/TESTING (10211): [MyCursorAdapter]bindView view : android.widget.LinearLayout@420171f0
04-09 11:05:10.657 E/TESTING (10211): [MyCursorAdapter]bindView imageView : android.widget.ImageView@423472d8

编辑:添加明确的问题

  • 这种行为是否正常?
  • 您建议如何实现我的目标/修复我的代码?

EDIT2:更多logcat

0 个答案:

没有答案