Android 如何在2D阵列中存储图像?

Android 如何在2D阵列中存储图像?,android,multidimensional-array,Android,Multidimensional Array,我想在2D数组中存储可绘制的图像 ImageView iv1[][] = new ImageView[2][20]; int mylist[][]={{R.drawable.step_000,R.drawable.step_001,R.drawable.step_002,R.drawable.step_003,R.drawable.step_004, R.drawable.step_005,R.drawable.step_006,R.drawable.step_007,R

我想在2D数组中存储可绘制的图像

ImageView iv1[][] = new ImageView[2][20];
    int mylist[][]={{R.drawable.step_000,R.drawable.step_001,R.drawable.step_002,R.drawable.step_003,R.drawable.step_004,
        R.drawable.step_005,R.drawable.step_006,R.drawable.step_007,R.drawable.step_008,R.drawable.step_009,R.drawable.step_010,
        R.drawable.step_011,R.drawable.step_012,R.drawable.step_013,R.drawable.step_014,R.drawable.step_015,R.drawable.step_016,
        R.drawable.step_017,R.drawable.step_018,R.drawable.step_019}, 

        {R.drawable.step_100,R.drawable.step_101,R.drawable.step_102,R.drawable.step_103,R.drawable.step_104,
        R.drawable.step_105,R.drawable.step_106,R.drawable.step_107,R.drawable.step_108,R.drawable.step_109,R.drawable.step_110,
        R.drawable.step_111,R.drawable.step_112,R.drawable.step_113,R.drawable.step_114,R.drawable.step_115,R.drawable.step_116,
        R.drawable.step_117,R.drawable.step_118,R.drawable.step_119}};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.data);
    iv=(ImageView)findViewById(R.id.imageView1);
    iv2=(ImageView)findViewById(R.id.left);
    iv3=(ImageView)findViewById(R.id.right);
    iv2.setVisibility(View.INVISIBLE);

    Bundle bundle=getIntent().getExtras();
    String value=bundle.getString("key");
    int step = getIntent().getExtras().getInt("steps");
    Toast.makeText(getApplicationContext(), ""+step,Toast.LENGTH_SHORT).show();

    int a;
    a=step;
    for(int i=0;i<20;i++)
    {
        for(int j=0; j<a; j++)
        iv1[i][j] = (ImageView)findViewById(mylist[i][j]);
    }


    if(value.contentEquals("cristiano"))
    {
    iv.setImageResource(mylist[i][j]);
    }

ImageView iv1[][]=新的ImageView[2][20];
int mylist[][]={{R.drawable.step_000,R.drawable.step_001,R.drawable.step_002,R.drawable.step_003,R.drawable.step_004,
R.可拉伸。步骤005,R.可拉伸。步骤006,R.可拉伸。步骤007,R.可拉伸。步骤008,R.可拉伸。步骤009,R.可拉伸。步骤010,
可拉深。步骤011,步骤012,步骤013,步骤014,步骤015,步骤016,
R.drawable.step_017,R.drawable.step_018,R.drawable.step_019},
{R.drawable.step_100,R.drawable.step_101,R.drawable.step_102,R.drawable.step_103,R.drawable.step_104,
可拉深。步骤105,步骤106,步骤107,步骤108,步骤109,步骤110,
可拉深。步骤111,步骤112,步骤113,步骤114,步骤115,步骤116,
R.drawable.步骤117,R.drawable.步骤118,R.drawable.步骤119};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.data);
iv=(ImageView)findViewById(R.id.imageView1);
iv2=(ImageView)findViewById(R.id.左);
iv3=(ImageView)findViewById(R.id.右侧);
iv2.设置可见性(视图不可见);
Bundle Bundle=getIntent().getExtras();
字符串值=bundle.getString(“键”);
int step=getIntent().getExtras().getInt(“步骤”);
Toast.makeText(getApplicationContext(),“”+步长,Toast.LENGTH_SHORT).show();
INTA;
a=步骤;

对于(int i=0;i似乎您正在使用两个for循环正确设置iv1 ImageView数组中的所有内容。问题是您正在将屏幕上的一个ImageView设置为整个数组,因此它只显示一个。您应该尝试对多个ImageView进行网格布局,然后逐个设置。我知道这一点这样做会很方便,但我认为没有办法让它像那样工作。此外,我认为
iv.setImageResource(mylist[I][j]);
会给您带来麻烦,因为它在循环之外,不知道
i
j
是什么。

我的20个图像没有运行..只有一个图像工作..ArrayIndexOutBoundException在最佳情况下ImageView iv1[]=new ImageView[2][20];for(int i=0;i@user3432085你的
if(value.contentEquals(“cristiano”)怎么样{iv.setImageResource(mylist[i][j]);}
未显示任何错误?您是否已全局声明了
i
j