【发布时间】:2018-01-12 09:05:26
【问题描述】:
public abstract class MainActivity extends Activity implements View.OnClickListener{
private ImageButton bt1;
public int index =0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Drawable[][] images = new Drawable[4][16];
bt1 = (ImageButton) findViewById(R.id.im_bt1);
bt1.setImageDrawable(images[index][(int)(Math.random()*16)]);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
index++;
((ImageButton)v).setImageDrawable(images[index][(int)(Math.random()*16)]);
}
});
}
Red RR1 = new Red(R.drawable.rr1);
Red RY1 = new Red(R.drawable.ry1);
Red RG1 = new Red(R.drawable.rg1);
Red RB1 = new Red(R.drawable.rb1);
Green GB1 = new Green(R.drawable.greenblue);
Green GG1 = new Green(R.drawable.greengreen);
Green GR1 = new Green(R.drawable.greenred);
Green GY1 = new Green(R.drawable.greenyellow);
Yellow YY1 = new Yellow(R.drawable.yellowyellow);
Yellow YB1 = new Yellow(R.drawable.yellowblue);
Yellow YG1 = new Yellow(R.drawable.yellowgreen);
Yellow YR1 = new Yellow(R.drawable.yellowred);
Blue BR1= new Blue(R.drawable.br1);
Blue BB1=new Blue(R.drawable.bb1);
Blue BY1=new Blue(R.drawable.by1);
Blue BG1= new Blue(R.drawable.bg1);
Red[] Redarray = new Red[]{
RR1,RY1,RG1,RB1
};
Green[] Greenarray = new Green[]{
GR1,GB1,GY1,GG1
};
Blue[] Bluearray = new Blue[]{
BB1,BY1,BG1,BR1
};
Yellow[] Yellowarray = new Yellow[]{
YB1,YG1,YR1,YY1
};
}
我的布局中有一个ImageButton,我想按下按钮并从一个数组中获取另一个随机ImageButton,当我按下那个时再获取另一个,但我希望它在数组上按顺序显示我做了。
图像数组 1 图像数组 2 图像数组 3 图像数组 4
从array1 到另一个随机图像按钮从array2 到另一个从array 3 的图像按钮...
编辑:所以我制作了一个包含所有数组的类,但它不起作用..我正在努力制作一个数组数组..你们可以检查我的代码吗?谢谢..
【问题讨论】:
-
请发布一些代码,展示您尝试过的内容,我们可以尝试向您展示您需要进行哪些更改才能使其正常工作。
-
好的,谢谢!我会得到更新
标签: java android imagebutton android-imagebutton