3

I use this code and found strange effect

 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 returns only 3 ROWs from DB. But in debug log I see:

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

But I'm waiting for just see only 3 rows in debug log If I put the commant "Log.d" before like this:

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

I see 27 rows in debug logs

Why ViewBuilder was called so many times? It's a feature or bug or my mistake ?

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

If put log before "if"

 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
koa7
  • 51
  • 5
  • `Log.d` parameter `columnIndex` and `cursor.getPosition` – pskink Nov 08 '15 at 11:41
  • I've added above more debug log – koa7 Nov 08 '15 at 11:57
  • add log statement at the top of `setViewValue`, and again log cursor position and column index – pskink Nov 08 '15 at 12:20
  • you may observe multiple calls for the first time, when you scroll down/up your list view content you should only see `setViewValue` to be called for a new positions – pskink Nov 08 '15 at 12:29
  • No, I get this log just after open ListFragment, I did't do anything more for getting log like this – koa7 Nov 08 '15 at 12:31
  • as i said it is called three times at the beginning but later on it is called properly, if you want to see it, remove Log.d from the ViewBinder and just for testing purposes override adapter's `bindView` method and Log.d position – pskink Nov 08 '15 at 12:33
  • Unfortunatly I can't see this because I have only 3 items at ListView and can only reopen ListFragment. Anyway it's a strange effect – koa7 Nov 08 '15 at 12:37
  • see [here](http://stackoverflow.com/questions/15297323/custom-cursor-adapter-calling-bindview-multiple-times) and similar topics, maybe aaronmarino's answer will help – pskink Nov 08 '15 at 12:39
  • Ok it's enought for me Thanks – koa7 Nov 08 '15 at 12:45

0 Answers0