我正在为 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,
};
}