答案 0 :(得分:1)
尝试以下代码:
从资源获取数组(您可以使用arraylist或任何数组)
final String[] mTestArray = getResources().getStringArray(R.array.hours_array);
用于警告对话框
new AlertDialog.Builder(MainActivity.this)
.setTitle(getString(R.string.app_name))
.setSingleChoiceItems(mTestArray, 0, null)
.setPositiveButton(R.string.txt_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
}
})
.setNegativeButton(R.string.txt_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.show();