Jump to content

viewbinder / setviewvalue appelé trop !


Olivier

Recommended Posts

J'ai un pb avec mon appli (ma première) : j'ai constaté dans les logs que mon setviewvalue était appelé très souvent (beaucoup trop je pense) et je ne comprend pas [color=red]pkoi[/color].

Voici un lien vers le screenshot de l'appli (2 lignes de données) : http://dl.free.fr/rndRtl1N9

J'ai une listview définie comme cela :

public class FreeboxMobileMeva extends Activity

{

private Cursor mMessagesCursor;

protected ListView list;

protected FreeboxMobileDbAdapter mDbHelper;

...

public void onStart()

{

super.onStart();

this.mDbHelper = new FreeboxMobileDbAdapter(this);

this.mDbHelper.open();

this.mMessagesCursor = mDbHelper.fetchAllMessages();

String[] from = new String[]{FreeboxMobileDbAdapter.KEY_SOURCE, FreeboxMobileDbAdapter.KEY_QUAND, FreeboxMobileDbAdapter.KEY_LENGTH};

int[] to = new int[]{R.id.source,R.id.quand, R.id.length};

SimpleCursorAdapter messages = new SimpleCursorAdapter(this, R.layout.messages_row, this.mMessagesCursor, from, to);

messages.setViewBinder(new MessageRow());

list.setAdapter(messages);

}

...

}

Puis :

public class MessageRow implements SimpleCursorAdapter.ViewBinder, Constants

{

public boolean setViewValue(View view, Cursor cursor, int columnIndex)

{

i++;

Log.d(DEBUGTAG,"MessageRow setViewValue "+columnIndex+" "+cursor.getPosition()+" "+i);

switch(view.getId())

{

case R.id.source:

Log.d(DEBUGTAG,"MessageRow Source");

TextView qui = (TextView)view.findViewById(R.id.source);

qui.setText(getContactNameFromNumber(cursor.getString(cursor.getColumnIndex(FreeboxMobileDbAdapter.KEY_SOURCE))));

return true;

case R.id.quand:

Log.d(DEBUGTAG,"MessageRow Quand");

TextView quand = (TextView)view.findViewById(R.id.quand);

quand.setText(cursor.getString(cursor.getColumnIndex(FreeboxMobileDbAdapter.KEY_QUAND)));

return true;

case R.id.length:

Log.d(DEBUGTAG,"MessageRow Length");

TextView length = (TextView)view.findViewById(R.id.length);

length.setText(String.valueOf(cursor.getInt(cursor.getColumnIndex(FreeboxMobileDbAdapter.KEY_LENGTH))));

return true;

}

return false;

}

private String getContactNameFromNumber(String number)

{

....

}

}

Ma ressource message_row.xml :

<?xml version="1.0" encoding="utf-8"?>

Au final le log produit (donc avec juste deux lignes de données) :

D/_FreeboxMobile( 5325): MessageRow setViewValue 3 0 1

D/_FreeboxMobile( 5325): MessageRow Source

D/_FreeboxMobile( 5325): MessageRow setViewValue 4 0 2

D/_FreeboxMobile( 5325): MessageRow Quand

D/_FreeboxMobile( 5325): MessageRow setViewValue 7 0 3

D/_FreeboxMobile( 5325): MessageRow Length

D/_FreeboxMobile( 5325): MessageRow setViewValue 3 1 4

D/_FreeboxMobile( 5325): MessageRow Source

D/_FreeboxMobile( 5325): MessageRow setViewValue 4 1 5

D/_FreeboxMobile( 5325): MessageRow Quand

D/_FreeboxMobile( 5325): MessageRow setViewValue 7 1 6

D/_FreeboxMobile( 5325): MessageRow Length

D/_FreeboxMobile( 5325): MessageRow setViewValue 3 0 7

D/_FreeboxMobile( 5325): MessageRow Source

D/_FreeboxMobile( 5325): MessageRow setViewValue 4 0 8

D/_FreeboxMobile( 5325): MessageRow Quand

D/_FreeboxMobile( 5325): MessageRow setViewValue 7 0 9

D/_FreeboxMobile( 5325): MessageRow Length

D/_FreeboxMobile( 5325): MessageRow setViewValue 3 1 10

D/_FreeboxMobile( 5325): MessageRow Source

D/_FreeboxMobile( 5325): MessageRow setViewValue 4 1 11

D/_FreeboxMobile( 5325): MessageRow Quand

D/_FreeboxMobile( 5325): MessageRow setViewValue 7 1 12

D/_FreeboxMobile( 5325): MessageRow Length

D/_FreeboxMobile( 5325): MessageRow setViewValue 3 0 13

D/_FreeboxMobile( 5325): MessageRow Source

D/_FreeboxMobile( 5325): MessageRow setViewValue 4 0 14

D/_FreeboxMobile( 5325): MessageRow Quand

D/_FreeboxMobile( 5325): MessageRow setViewValue 7 0 15

D/_FreeboxMobile( 5325): MessageRow Length

D/_FreeboxMobile( 5325): MessageRow setViewValue 3 1 16

D/_FreeboxMobile( 5325): MessageRow Source

D/_FreeboxMobile( 5325): MessageRow setViewValue 4 1 17

D/_FreeboxMobile( 5325): MessageRow Quand

D/_FreeboxMobile( 5325): MessageRow setViewValue 7 1 18

D/_FreeboxMobile( 5325): MessageRow Length

En gros chaque case du switch est appelé 6 fois (je m'attendais à 2, un par ligne).

J'ai cherché mais je ne vois pas là :-(

Merci !

Edited by Olivier
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...