我检查了数组 menuItems 看起来不错,但是下面的代码有问题。当我开始时它似乎还可以,但是当我开始滚动时它会搞砸并将项目放在列表顶部并重复项目......这很奇怪
public class ScoresAdapter extends BaseAdapter {
private MainActivity activity;
private ScoreItem[] menuItems;
private static LayoutInflater inflater=null;
ImageDownloader downloader;
public ScoresAdapter(MainActivity a, ScoreItem[] scoreItems) {
activity = a;
menuItems = scoreItems;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
downloader = new ImageDownloader();
}
public int getCount() {
int teller = 0;
for(int i = 0 ; menuItems.length > i ; i++){
if(menuItems[i] != null){
teller++;
}
}
return teller;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null){
if(menuItems[position].getId() == 888){
//fav header
vi = inflater.inflate(R.layout.scoresheaderfavoriet, null);
}else if(menuItems[position].getId() == 999){
//overige header
vi = inflater.inflate(R.layout.scoresheaderoverig, null);
}else{
if(menuItems[position].getIsFav()){
vi = inflater.inflate(R.layout.scoresfavitem, null);
}else{
vi = inflater.inflate(R.layout.scoresitem, null);
}
TextView text2=(TextView)vi.findViewById(R.id.position);
text2.setText(""+ menuItems[position].getPosition());
TextView text=(TextView)vi.findViewById(R.id.name);
text.setText(menuItems[position].getFirstName() + " " + menuItems[position].getLastName().toUpperCase());
TextView text5=(TextView)vi.findViewById(R.id.country);
text5.setText(""+ menuItems[position].getCountry());
TextView text3=(TextView)vi.findViewById(R.id.score);
text3.setText(""+ menuItems[position].getScore());
TextView text8=(TextView)vi.findViewById(R.id.hole);
text8.setText(""+ menuItems[position].getHole());
vi.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), SpelerView.class);
intent.putExtra("id", menuItems[position].getId());
v.getContext().startActivity(intent);
activity.sluitAlleMenus();
}
});
}
}
return vi;
}
}