我是android开发的新手。我正在以编程方式创建RadioButton但是我发现了这个错误:
错误的州级,期待View State但是收到了类android.widget.CompoundButton $ SavedState。当两个不同类型的视图在同一层次结构中具有相同的id时,通常会发生这种情况。该视图的id为id / 0x4。确保其他视图不使用相同的ID。
我的代码是:: DynamicFormCreation.java
function translateAlong(path) {
return function(d, i, a) {
return function(t) {
var p = path.getPointAtLength(t*data.length*100);
// Update the text inside the text element:
text.text("X is " + p.x + "Y is " + p.y);
return "translate(" + p.x + "," + p.y + ")";
};
};
}
调用该函数::
public RadioGroup createRadioButton(String[] option, Context context, int parentId) {
final RadioButton[] rb = new RadioButton[5];
RadioGroup rg = new RadioGroup(context);
rg.setPadding(5, 5, 0, 5);
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(metrics);
final float width = metrics.widthPixels;
rg.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
rg.setMinimumHeight(UtilityClass.intToDpi(65, context));
rg.setOrientation(RadioGroup.HORIZONTAL);
for (int i = 0; i < 5; i++) {
if (option[i] != null && option[i].trim().length() > 0) {
rb[i] = new RadioButton(context);
rg.addView(rb[i]);
rb[i].setTextColor(Color.BLACK);
rb[i].setText(option[i]);
}
}
return rg;
}
在activity ::
中调用此类RadioGroup relgroup = createRadioButton(option, context, parentId);
rel.addView(relgroup);
parentId++;