I’m creating an Android app that displays tv-shows on a listview. My shows coming up in the ListView, but they switch places one scrolls.
They are created as costum listview and the class is here:
public class CustomListViewAdapter extends BaseAdapter {
private static ArrayList<Show> searchArrayList;
private LayoutInflater mInflater;
private TextView txtTitle, txtPrev, txtNext;
public CustomListViewAdapter(Context context, ArrayList<Show> results) {
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row, null);
txtTitle = (TextView) convertView.findViewById(R.id.title);
txtPrev = (TextView) convertView.findViewById(R.id.prevNrDate);
txtNext = (TextView) convertView.findViewById(R.id.nextNrDate);
}
txtTitle.setText(searchArrayList.get(position).getTitle());
txtPrev.setText(searchArrayList.get(position).getPrevNr() + " - " +
searchArrayList.get(position).getPrevDate() + "\n" +
searchArrayList.get(position).getPrevTitle());
txtNext.setText(searchArrayList.get(position).getNextNr() + " - " +
searchArrayList.get(position).getNextDate() + "\n" +
searchArrayList.get(position).getNextTitle());
return convertView;
}
}
Some one who can help?
//Casper
It looks like you were trying to implement a
ViewHolderto save the extrafindViewByIdcalls when using recycled views. The problem is that you’re storing those views per-adapter instead of per-recycled view. You need to create a separateViewHolderobject and store it along with each view. The view’s tag is a good place to do this.Try this: