0
我需要幫助,我有表格3x3。點擊後如何在gridView中重新加載圖像?我想讓簡單的應用程序1好點擊= 1點。點擊後重新載入圖片
public void losowanieTablicy() {
int[] str_names = {0, 1, 2, 3, 4, 5, 6, 7, 8};
shuffle(str_names);
shuffle(imgIds);
for (int i = 0; i < imgIds.length; i++) {
ImageView img = (ImageView) findViewById(imgIds[i]);
final String str = "img_" + str_names[i]; // zakladajac ze str_names.length == imgIds.length
img.setImageDrawable(
getResources().getDrawable(getResourceID(str, "mipmap", getApplicationContext()))
);
}
}
public void shuffle(int[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
// between i and n-1
int r = i + (int)(Math.random() * (n - i));
int tmp = a[i]; // swap
a[i] = a[r];
a[r] = tmp;
}
}
你可以使用一個onClickListener您ImageView的再定義,通過圖像 –
數組循環,你能不能給我任何的例子,一個函數? – Kubequ