我正在实现子视图的复选框和单选按钮。我也夸大了不同的布局。但问题是我使用了if和else语句的视图和always else语句执行而不访问if语句谁能告诉我我在这里做错了什么?我想为我的孩子准备一个chceckbox,但总是会出现radioButton。
public class ExpandableListItem {
public static final int CHILD_TYPE_EDITTEXT = 0;
public static final int CHILD_TYPE_TEXT_FIELD = 1;
public static final int CHILD_TYPE_RADIO_BUTTON = 2;
public static final int CHILD_TYPE_CHECKBOX = 3;
private List<String> childLabels;
private String title;
private int selectionType;
public List<String> getChildLabels() {
return childLabels;
}
public void setChildLabels(List<String> childLabels) {
this.childLabels = childLabels;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getSelectionType() {
return selectionType;
}
public void setSelectionType(int selectionType) {
this.selectionType = selectionType;
}}
这是我的适配器:
@Override
public View getChildView(int listPosition, final int expandedListPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
String childLabel = expandableListItemList.get(listPosition).getChildLabels().get(expandedListPosition);
switch (expandableListItemList.get(listPosition).getSelectionType()) {
case ExpandableListItem.CHILD_TYPE_CHECKBOX:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.checkbox, null);
((CheckBox)convertView.findViewById(R.id.checkfor_Child)).setText(childLabel);
break;
case ExpandableListItem.CHILD_TYPE_EDITTEXT:
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.plaintext, null);
break;
case ExpandableListItem.CHILD_TYPE_RADIO_BUTTON:
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.radiobutton, null);
((RadioButton)convertView.findViewById(R.id.radiofor_child)).setText(childLabel);
break;
default:
case ExpandableListItem.CHILD_TYPE_TEXT_FIELD:
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.textbox, null);
break;
}
return convertView;
}
这是在我的Builder类里面的create:
private ArrayList<ExpandableListItem> getchildExpandableListItem() {
final ArrayList<ExpandableListItem> expandableListItemList = new ArrayList<>();
ExpandableListItem expandableListItem = new ExpandableListItem();
expandableListItem.setTitle(getIntent().getStringExtra("Heading"));
List<String> childLabels = new ArrayList<>();
childLabels = getIntent().getStringArrayListExtra("options");
expandableListItem.setChildLabels(childLabels);
if (expandableListItem.getSelectionType()== 2) {
expandableListItem.setSelectionType(ExpandableListItem.CHILD_TYPE_CHECKBOX);
} else {
expandableListItem.setSelectionType(ExpandableListItem.CCHILD_TYPE_RADIO_BUTTON);
}
expandableListItemList.add(expandableListItem);
return expandableListItemList;
}
我认为在if语句中分配2所以它不会被执行并转到else语句。我能在这做什么?
答案 0 :(得分:0)
检查
expandableListItem.getSelectionType()
此值我认为它不会返回2,因此您每次都会收到单选按钮而非复选框,因此请检查数据将落入您的应用中
快乐的Codding !!