它如何在Android上运行setViewBinder?

时间:2015-11-08 11:33:40

标签: android simplecursoradapter

我使用此代码并发现奇怪的效果

 mAdapter = new SimpleCursorAdapter(getActivity(),
                R.layout.cards_list, null,
                new String[]{DataBaseHelper.NAME, DataBaseHelper.PAN, DataBaseHelper.CARD_ID },
                new int[] {R.id.cardsName, R.id.cardsPAN, R.id.imgCardType }, 0);

mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                if (view.getId() == R.id.imgCardType) {
                    i++;
                    Log.d("MYDRBUG", "How many times ? :"+String.valueOf(i));
                    return true;
                }
                return false;
            }
        });

Cursor仅从DB返回3个ROW。 但在调试日志中我看到:

D/MYDRBUG: How many times ? :1
D/MYDRBUG: How many times ? :2
D/MYDRBUG: How many times ? :3
D/MYDRBUG: How many times ? :4
D/MYDRBUG: How many times ? :5
D/MYDRBUG: How many times ? :6
D/MYDRBUG: How many times ? :7
D/MYDRBUG: How many times ? :8
D/MYDRBUG: How many times ? :9

但是我等待调试日志中只看到3行 如果我把commant" Log.d"在此之前:

i++;
Log.d("MYDRBUG", "How many times ?
if (view.getId() == R.id.imgCardType) {
                         :"+String.valueOf(i));

我在调试日志中看到27行

为什么多次调用ViewBuilder? 这是一个功能或错误还是我的错误?

Log.d("MYDRBUG", "How many times ? :"+String.valueOf(i)+"  columnIndex :"+ String.valueOf(columnIndex)+"  cursor.getPosition :"+String.valueOf(cursor.getPosition()));



 D/MYDRBUG: How many times ? :1  columnIndex :1  cursor.getPosition :0
 D/MYDRBUG: How many times ? :2  columnIndex :1  cursor.getPosition :1
 D/MYDRBUG: How many times ? :3  columnIndex :1  cursor.getPosition :2
 D/MYDRBUG: How many times ? :4  columnIndex :1  cursor.getPosition :0
 D/MYDRBUG: How many times ? :5  columnIndex :1  cursor.getPosition :1
 D/MYDRBUG: How many times ? :6  columnIndex :1  cursor.getPosition :2
 D/MYDRBUG: How many times ? :7  columnIndex :1  cursor.getPosition :0
 D/MYDRBUG: How many times ? :8  columnIndex :1  cursor.getPosition :1
 D/MYDRBUG: How many times ? :9  columnIndex :1  cursor.getPosition :2

如果在&#34之前放入日志;如果"

 D/MYDRBUG: How many times ? :1  columnIndex :2  cursor.getPosition :0
 D/MYDRBUG: How many times ? :2  columnIndex :3  cursor.getPosition :0
 D/MYDRBUG: How many times ? :3  columnIndex :1  cursor.getPosition :0
 D/MYDRBUG: How many times ? :4  columnIndex :2  cursor.getPosition :1
 D/MYDRBUG: How many times ? :5  columnIndex :3  cursor.getPosition :1
 D/MYDRBUG: How many times ? :6  columnIndex :1  cursor.getPosition :1
 D/MYDRBUG: How many times ? :7  columnIndex :2  cursor.getPosition :2
 D/MYDRBUG: How many times ? :8  columnIndex :3  cursor.getPosition :2
 D/MYDRBUG: How many times ? :9  columnIndex :1  cursor.getPosition :2
 D/MYDRBUG: How many times ? :10  columnIndex :2  cursor.getPosition :0
 D/MYDRBUG: How many times ? :11  columnIndex :3  cursor.getPosition :0
 D/MYDRBUG: How many times ? :12  columnIndex :1  cursor.getPosition :0
 D/MYDRBUG: How many times ? :13  columnIndex :2  cursor.getPosition :1
 D/MYDRBUG: How many times ? :14  columnIndex :3  cursor.getPosition :1
 D/MYDRBUG: How many times ? :15  columnIndex :1  cursor.getPosition :1
 D/MYDRBUG: How many times ? :16  columnIndex :2  cursor.getPosition :2
 D/MYDRBUG: How many times ? :17  columnIndex :3  cursor.getPosition :2
 D/MYDRBUG: How many times ? :18  columnIndex :1  cursor.getPosition :2
 D/MYDRBUG: How many times ? :19  columnIndex :2  cursor.getPosition :0
 D/MYDRBUG: How many times ? :20  columnIndex :3  cursor.getPosition :0
 D/MYDRBUG: How many times ? :21  columnIndex :1  cursor.getPosition :0
 D/MYDRBUG: How many times ? :22  columnIndex :2  cursor.getPosition :1
 D/MYDRBUG: How many times ? :23  columnIndex :3  cursor.getPosition :1
 D/MYDRBUG: How many times ? :24  columnIndex :1  cursor.getPosition :1
 D/MYDRBUG: How many times ? :25  columnIndex :2  cursor.getPosition :2
 D/MYDRBUG: How many times ? :26  columnIndex :3  cursor.getPosition :2
 D/MYDRBUG: How many times ? :27  columnIndex :1  cursor.getPosition :2

0 个答案:

没有答案