我想要得到它,這樣,當圖像1顯示,一個TextView顯示其名稱Android的BaseAdapter,退貨項目編號
這裏是我的名字的數組
String[] soundcloudDates = {
"Image 1",
"Image 2",
"Image 3",
"Image 4",
};
,這是我的BaseAdapter使用來自GitHub的EcoGallery庫 所有圖像都能正確滾動,但是它們的輸出爲全部位置 更多時候它開始打印輸出位置= 1 ;,直到位置= 3時纔會更改;
private class ImageAdapter extends BaseAdapter {
private Context context;
ImageAdapter(Context context) {
this.context = context;
}
public int getCount() {
return 4;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// Not using convertView for simplicity. You should probably use it
// in real application to get better performance.
ImageView imageView = new ImageView(context);
int resId;
switch (position) {
case 0:
resId = R.drawable.logo;
position = 0;
dateView.setText(soundcloudDates[position]);
break;
case 1:
resId = R.drawable.soundcloudtest;
position = 0;
dateView.setText(soundcloudDates[position]);
break;
case 2:
resId = R.drawable.logo;
position = 0;
dateView.setText(soundcloudDates[position]);
break;
case 3:
resId = R.drawable.ic_launcher;
position = 0;
dateView.setText(soundcloudDates[position]);
break;
default:
resId = R.drawable.ic_launcher;
}
imageView.setImageResource(resId);
return imageView;
}
}
我已經嘗試將setText()放在不同的地方,不起作用。
我不明白什麼即時做錯了:(任何幫助將是巨大的
你爲什麼要設置'位置= 0' – Apoorv
這是從一個遺留下來的我?試圖將位置傳遞迴一個全局變量,看看這是否會工作 –