Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.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 如何使用变量作为getResourceId(int-index,int-defValue)中的索引;_Android_Sharedpreferences_Android Resources - Fatal编程技术网

Android 如何使用变量作为getResourceId(int-index,int-defValue)中的索引;

Android 如何使用变量作为getResourceId(int-index,int-defValue)中的索引;,android,sharedpreferences,android-resources,Android,Sharedpreferences,Android Resources,我使用以下代码定义背景按钮: TypedArray bottombuttons = res.obtainTypedArray(R.array.bottombuttons ); button0.setBackgroundResource(bottombuttons .getResourceId(index, 1)); 其中index是来自共享活动的变量 int index = themePref.getInt("index", 1); 答案是我必须在onResume()中进行更改,而不是在o

我使用以下代码定义背景按钮:

TypedArray bottombuttons = res.obtainTypedArray(R.array.bottombuttons );

button0.setBackgroundResource(bottombuttons .getResourceId(index, 1));
其中
index
是来自共享活动的变量

int index = themePref.getInt("index", 1);

答案是我必须在
onResume()
中进行更改,而不是在
onCreate()
中进行更改答案是我必须在
onResume()
中进行更改,而不是在
onCreate()