【发布时间】:2011-10-04 10:55:09
【问题描述】:
@@ Branislav-我和你说的一样。它对我有用,但是当没有图像超过 9 n 个文本时,它也开始在第 9 个图像的位置显示相同的第一个或蚂蚁随机图像和文本文字
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.mainmenu, null);
TextView tv = (TextView)v.findViewById(R.id.icon_text);
tv.setText(mTextsIds[position]);
ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
iv.setImageResource(mThumbIds[position]);
} else {
v = (View) convertView;
}
return v;
}
private Integer[] mThumbIds = {
R.drawable.hotel1, R.drawable.rest,R.drawable.dubaicityinfoicon_new,R.drawable.history1,R.drawable.geography,R.drawable.infoicon,R.drawable.infoicon,R.drawable.infoicon,R.drawable.parkmain,
};
// references to our texts
private String[] mTextsIds = {
"Hotels","Restaurants","City Info","Dubai History","Geography Of Dubai","Useful Information","Embassies in Duabai","Museum's","park"
};
在这个博物馆里它很完美,但对于公园它不起作用;它显示数组 mThumbIds 中的任何随机图像和相关文本。是的,该图像是可绘制的。
【问题讨论】:
-
@@Dr.nik- 我在你说的教程中做过 sme wat tey。仍然面临问题
标签: android image gridview text