2
基本上我在这里有三(3)个复选框列表中的三(3)个不同的片段。当我打开活动时,默认片段中的复选框显示为正常,但不同片段中的显示不同。该复选框的值仍然为真。下面是复选框的图像,使事情更清晰,也是我的代码。复选框值为true,但是tick不显示 - Android/Java
第一个片段页:
第二个片段页:
代码设置的复选框,其if condition
private void setCheckBox(ArrayList<DataPrefType> arrayList){
for(int i = 0; i < arrayList.size(); i++){
id = i + 1;
checkBox = new CheckBox(getActivity());
checkBox.setId(i + 1);
checkBox.setText(arrayList.get(i).getName());
checkBox.setPadding(10, 10, 10, 10);
checkBox.setLayoutParams(params);
checkBox.setGravity(Gravity.CENTER);
checkBoxLayout.addView(checkBox);
if(!userPreference.isEmpty() || userPreference != null){
for(int j = 0; j < userPreference.get(0).getDataPrefTypeArrayList().size(); j++){
int retrieveId = Integer.parseInt(userPreference.get(0).getDataPrefTypeArrayList().get(j).getId());
if(checkBox.getId() == retrieveId)
checkBox.setChecked(true);
}
}
不是答案,而是提示......在你的第一个if语句中,如果'userPreference'为null(在'!userPreference.isEmpty()'之前)并且用'&&'替换'||'所以两个条件都必须为真 – Tyrmos
好的。谢谢你的提示:) –
我面临完全相同的问题。我在标签活动中有2个不同的片段,每个片段都带有复选框。我将数据加载到基于OnViewCreated的复选框中。在第二个片段中,真正的复选框突出显示而不是打勾。由于选项卡式活动,我感觉它是一个问题。 – xSooDx