Używam widza do wyświetlania z dynamicznego arrayadapter.it działa, ale wyświetlane dane zmieniają się nieregularnie po przewinięciu listy. Chcę, aby mój widok listy był wypełniany tylko raz, Nie cały czas, kiedy przewijam listę. Jakieś sugestie? Oto mój kodJak zaimplementować uchwyt do widoku?
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.
if (convertView == null) {
convertView = mInflater.inflate(R.layout.sample, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
if(_first==true)
{
if(id<myElements.size())
{
holder.name.setText(myElements.get(id));
holder.icon.setImageBitmap(mIcon1);
id++;
}
else
{
_first=false;
}
}
//holder.icon.setImageBitmap(mIcon2);
/*try{
if(id<myElements.size())
id++;
else
{
id--;
}
}
catch(Exception e)
{
android.util.Log.i("callRestService",e.getMessage());
}*/
return convertView;
}
static class ViewHolder {
TextView name;
ImageView icon;
}
gdy lista jest ładowany wygląda to tak: http://i.stack.imgur.com/NrGhR.png po przewinięciu niektóre dane http://i.stack.imgur.com/sMbAD.png wygląda to tak, i jeszcze raz, gdybym przewinąć do początku wygląda http://i.stack.imgur.com/0KjMa.png
PS: moja lista musi być w porządku alfabetycznym
można opublikować zrzut ekranu z wydrukiem? –
@Tilsan The Fighter: opublikowali migawki. – Ads