我正在为Android开发一个应用程序,并希望使用GridView构建带有图标的菜单。为此,我使用http://www.edumobile.org/android/android-beginner-tutorials/draw-menu-in-grid-view/已有的解决方案,但结果系统显示 mThumbIds - 无法解析为变量,当我尝试声明时它作为一个新的局部变量,错误仍然存在。我是Android的新手,可能犯了很简单的错误,但我不能自己解决。所以,任何建议都会有所帮助。这是代码:
public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(45, 45));
imageView.setAdjustViewBounds(false);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
private Context mContext;
private Integer[] mThumIbs = {
R.drawable.ic_cards, R.drawable.ic_bank,
R.drawable.ic_currency, R.drawable.ic_calc,
R.drawable.ic_banking, R.drawable.ic_call,
};
}
答案 0 :(得分:0)
你有一个错字:
private Integer[] mThumIbs = {
R.drawable.ic_cards, R.drawable.ic_bank,
R.drawable.ic_currency, R.drawable.ic_calc,
R.drawable.ic_banking, R.drawable.ic_call,
};
而不是 mThumbIbs ,这不应该是 mThumbIds 吗?