Olivier Posted November 18, 2009 Share Posted November 18, 2009 (edited) 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 November 18, 2009 by Olivier Quote Link to comment Share on other sites More sharing options...
popolbx Posted November 18, 2009 Share Posted November 18, 2009 bein non.... ya 3 cas. il est appelé pour chaque view de ta ligne donc 6. sinon tu ne rentre qu'une fois dans le case. Quote Link to comment Share on other sites More sharing options...
Olivier Posted November 18, 2009 Author Share Posted November 18, 2009 Ok merci , mais du coup, comment faire pour ne pas rentrer 6 fois dans le "case R.id.source:" par exemple mais seulement 2 ? Afin qu'il n'execute pas 6 fois getContactNameFromNumber() mais seulement 2. Cordialement, Olivier Quote Link to comment Share on other sites More sharing options...
Olivier Posted November 18, 2009 Author Share Posted November 18, 2009 En passant de : public class FreeboxMobileMevo extends Activity à : public class FreeboxMobileMeva extends ListActivity Ce n'est plus appelé que 16 fois au lieu de 24. Mais toujours 4 appels par case (au lieu de 2 dans le meilleur cas). Quote Link to comment Share on other sites More sharing options...
Olivier Posted November 18, 2009 Author Share Posted November 18, 2009 popolbx : dans les traces, chaque case est appelé 4 fois (6 fois sur le log qui est posté). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.