Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何确定哪个TextView连接到哪个阵列?_Android_Arrays_For Loop_Textview - Fatal编程技术网

Android 如何确定哪个TextView连接到哪个阵列?

Android 如何确定哪个TextView连接到哪个阵列?,android,arrays,for-loop,textview,Android,Arrays,For Loop,Textview,我想在for循环中设置TextView的背景。 但是因为不能使用数组作为文本视图的名称,所以我不知道如何做到这一点 findViewById(R.id.array[x]).setBackgroundColor(Color.parseColor("#ffb6c1")); 我的文本视图被称为:array1,array2,array3 我想用数字代替[x]。 像这样: for (int x=1;x<13;x++){ findViewById(R.id.array[x]).setBack

我想在for循环中设置TextView的背景。 但是因为不能使用数组作为文本视图的名称,所以我不知道如何做到这一点

findViewById(R.id.array[x]).setBackgroundColor(Color.parseColor("#ffb6c1"));
我的文本视图被称为:array1,array2,array3

我想用数字代替[x]。 像这样:

for (int x=1;x<13;x++){
    findViewById(R.id.array[x]).setBackgroundColor(Color.parseColor("#ffb6c1"));
}

对于(intx=1;x您可以尝试以下操作

Resources res = getResources();

for (int x = 1; x < 13; x++){

    int id = res.getIdentifier("array" + x, "id", getContext().getPackageName());
    findViewById(id).setBackgroundColor(Color.parseColor("#ffb6c1"));
}
Resources res=getResources();
对于(int x=1;x<13;x++){
int id=res.getIdentifier(“数组”+x,“id”,getContext().getPackageName());
findViewById(id).setBackgroundColor(Color.parseColor(“#ffb6c1”);
}

是否将
TextView
id保存在数组中?否,我在数组中有字符串(数组[1]、数组[2]、数组[3]…)这些数组显示在TextView(数组1、数组2、数组3…)中。我想自动将连接的数组分配给正确的数组。数组[1]=array1数组[2]=array2,但文本视图的数字是(array1、array2、array3…)应自动添加。数组[1]应更改为array1等。这些
textView
是否存在于XML中?是的,我只想更改它们的背景