使用变量Integer

时间:2014-08-05 20:28:22

标签: android

我有一个变量整数,我不知道如何使用它

这是我的代码:

public class ImgAdapter extends BaseAdapter {
    private Context mContext;
    private ColorMatrixColorFilter cf;
    public static int level = Levels.level;

    public ImgAdapter(Context c) {
        mContext = c;
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0); //0 means grayscale
        cf = new ColorMatrixColorFilter(matrix);
    }

    public int getCount() {

        return ThumbIds.length; // I want a way to add level after ThumbIds
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;

        imageView = (ImageView) convertView;
        imageView = new ImageView(mContext);
        int size = mContext.getResources().getDimensionPixelSize(R.dimen.width);
        imageView.setLayoutParams(new GridView.LayoutParams(size, size));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setAdjustViewBounds(true);
        imageView.setImageResource(ThumbIds[position]);


        return imageView;
    }

    public static Integer[] ThumbIds1 =
    {
        R.drawable.question1,
        R.drawable.question2
    };
    public static Integer[] ThumbIds2 =
    {
        R.drawable.question3,
        R.drawable.question4
    };
    public static Integer[] ThumbIds3 =
    {
        R.drawable.question5,
        R.drawable.question6
    };
    public static Integer[] ThumbIds4 =
    {
        R.drawable.question9,
        R.drawable.question10
    };


}

级别是可变的(1或2或3或4)

我想在ThumbIds之后添加整数级别(ThumbIdsX,其中x是整数级别)
有没有办法做到这一点?

1 个答案:

答案 0 :(得分:1)

你想要的是一个ArrayList ThumbIds。

ArrayList<ThumbIds> list = new ArrayList<ThumbIds>();

因此,您可以使用push添加到数组,并使用get。

获取特定的ThumbIds