Android以编程方式重新分配视图ID

时间:2016-01-09 13:26:45

标签: java android android-studio

当尝试更改imageView的ID时,id不会改变,就像我希望它们改变一样,我知道它不是很清楚,但这里有一些我的代码:

row1Image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            row1Image.setImageResource(android.R.color.transparent);
            row2Image.setImageResource(android.R.color.transparent);
            row3Image.setImageResource(android.R.color.transparent);
            row4Image.setImageResource(android.R.color.transparent);
            row5Image.setImageResource(android.R.color.transparent);

        row1tile = row1ids[row2tileRand];
        row1Image.findViewById(row1tile);
        //i already tried using row1image = (ImageView)findViewById(row1tile); But that didn't work
        row1Image.setImageResource(R.drawable.audi_logo);


        row2tile = row2ids[row3tileRand];
        row2Image.findViewById(row2tile);
        row2Image.setImageResource(R.drawable.audi_logo);


        row3tile = row3ids[row4tileRand];
        row3Image.findViewById(row3tile);
        row3Image.setImageResource(R.drawable.audi_logo);


        row4tile = row4ids[row5tileRand];
        row4Image.findViewById(row4tile);
        row4Image.setImageResource(R.drawable.audi_logo);

        row5tileRand = random1.nextInt(max-min+1)-min;
        row5tile = row5ids[row5tileRand];
        row5Image.findViewById(row5tile);
        row5Image.setImageResource(R.drawable.audi_logo);
    }
});

如您所见,我首先将imageview的颜色更改为透明,然后我希望它在与上面相同的列中显示图像。这是我启动应用程序时的图像:

enter image description here

当我点击它时它会保持不变。

0 个答案:

没有答案