appel plusieurs fois à getView d'un BaseAdapter
Bonjour à tous ,
Voilà , je débute et tente de développer mon propre adapter pour une ListView
Code:
1 2 3 4 5 6
|
public void onCreate(Bundle savedInstanceState) {
...
String[] test={"aaa","bbb","ccc","eee","fff","ggg"};
StringAdapter ca=new StringAdapter(this, test);
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
public class StringAdapter extends BaseAdapter{
private Context mContext;
LayoutInflater inflater;
private String[] elements;
public CategoryAdapter(Context context,String[] list){
elements = list;
mContext=context;
inflater=LayoutInflater.from(mContext);
}
public int getCount() {
return elements.length;
}
public Object getItem(int position) {
return (String) elements[position];
}
public long getItemId(int position) {
return (long) position;
}
public View getView(int position, View convertView, ViewGroup parent) {
Log.i("INFO","getView StringAdapter "+position);
LinearLayout item;
if(convertView == null){
item = (LinearLayout) inflater.inflate(
R.layout.category_layout, parent, false);
}else{
item = (LinearLayout) convertView;
}
String c = elements[position];
TextView nomCategory=(TextView) item.findViewById(R.id.nomCategory);
nomCategory.setText(c);
LinearLayout mainItem=(LinearLayout) item.findViewById(R.id.LayoutMain);
mainItem.setTag(position);
return item;
}
} |
Jusque là , aucun pb , tout fonctionne sans pb , cependant , lorsque je regarde le logcat j'apercois que j'ai un appel plusieurs fois à la méthode getView de StringAdapter lors du chargement de la liste.
11-29 10:12:02.452: INFO/INFO(445): getView StringAdapter 0
11-29 10:12:02.482: INFO/INFO(445): getView StringAdapter 1
11-29 10:12:02.482: INFO/INFO(445): getView StringAdapter 2
11-29 10:12:02.492: INFO/INFO(445): getView StringAdapter 3
11-29 10:12:02.542: INFO/INFO(445): getView StringAdapter 0
11-29 10:12:02.542: INFO/INFO(445): getView StringAdapter 1
11-29 10:12:02.571: INFO/INFO(445): getView StringAdapter 2
11-29 10:12:02.592: INFO/INFO(445): getView StringAdapter 3
11-29 10:12:02.632: INFO/INFO(445): getView StringAdapter 0
11-29 10:12:02.672: INFO/INFO(445): getView StringAdapter 1
11-29 10:12:02.683: INFO/INFO(445): getView StringAdapter 2
11-29 10:12:02.683: INFO/INFO(445): getView StringAdapter 3
Quelqu'un saurait-il à quoi est du ces nombreux appels de getView ?
Pour info , je ne fait juste qu'un chargement de la liste , je ne la scroll pas, je ne fais rien du tout