我有以下代码:
LinearLayout myScrollLinearLayout = (LinearLayout) findViewById(R.id.scrolllinear);
Resources res = getBaseContext().getResources();
// loop for every file in raw folder
Field[] fields = R.raw.class.getFields();
Button[] buttons = new Button[fields.length];
for (int count = 0; count < fields.length; count++) {
final int counti = count;
buttons[count] = new Button(this);
buttons[count].setText("Wallpaper " + count);
buttons[count].setId(100+count);
int animId = res.getIdentifier("anim" + count, "raw",
getBaseContext().getPackageName());
buttons[count].setBackgroundResource(animId);
buttons[count].setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onSetWallpaper(counti);
}
});
myScrollLinearLayout.addView(buttons[count]);
}
图像很好,但它们是听众的问题 因为它正在崩溃 onSetWallpaper(counti);