我正在尝试在微调器中添加一些radiobuttons。但是我想通过仅使用java来实现这一点。我已经看到很多例子展示了如何使用xml资源,但没有这样的。由于某种原因,从阵列获取资源的人对我不起作用。这是我的代码
spinnerrg = new Spinner(con);
NodeList rl = child.getChildNodes();
String[] radioadapt = new String[rl.getLength()];
for(int j=1;j<rl.getLength();j++) {
Element[] dumrad = new Element[rl.getLength()];
Node dum = rl.item(j);
if(dum instanceof Element) {
dumrad[j] = (Element) dum;
radioadapt[j] = dumrad[j].getAttribute("value");
}
}
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(con, android.R.layout.simple_spinner_item, radioadapt);
spinnerrg.setAdapter(adapter);
TextView radioText = new TextView(con);
radioText.setText(child.getAttribute("label"));
spinnerrg.setTag(child.getAttribute("id"));
contList.add(radioText);
contList.add(spinnerrg);
那个nodeList在那里,因为我正在解析一个xml文件。如果我只是使用radiogroup但是无法通过微调器来完成它,那么for循环可以完美地工作。
答案 0 :(得分:0)
看看这个
spinnerrg = new Spinner(con);
//RadioGroup rg = new RadioGroup(con);
NodeList rl = child.getChildNodes();
Vector<String> radioadapt = new Vector<String>();
for(int j=0;j<rl.getLength();j++) {
Element[] dumrad = new Element[rl.getLength()];
Node dum = rl.item(j);
if(dum instanceof Element) {
//RadioButton rb = new RadioButton(con);
dumrad[j] = (Element) dum;
//rb.setHint(dumrad[j].getAttribute("value"));
radioadapt.add(dumrad[j].getAttribute("value"));
//rg.addView(rb);
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(con, android.R.layout.simple_spinner_item, radioadapt);
spinnerrg.setAdapter(adapter);
TextView radioText = new TextView(con);
radioText.setText(child.getAttribute("label"));
//spinnerrg.setTag(child.getAttribute("id"));
contList.add(radioText);
contList.add(spinnerrg);