Android 无线按钮动态
我有一个编辑文本,这取决于编辑文本中给出的数字我必须创建一个单选按钮,但我得到的错误这是我的代码Android 无线按钮动态,android,Android,我有一个编辑文本,这取决于编辑文本中给出的数字我必须创建一个单选按钮,但我得到的错误这是我的代码 public void onCreate(Bundle icicle) { super.onCreate(icicle); // ToDo add your GUI initialization code here setContentView(R.layout.main); go=(Button)findViewById(R.id.g
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
setContentView(R.layout.main);
go=(Button)findViewById(R.id.go);
no=(EditText)findViewById(R.id.noofradio);
err=(TextView)findViewById(R.id.err);
go.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
try
{
int a = Integer.parseInt(no.getText().toString());
RadioGroup radiogroup = new RadioGroup(MainActivity.this);
LinearLayout.LayoutParams rg = new RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
for (int i = 0; i < a; i++) {
radiobutton = new RadioButton(MainActivity.this);
radiobutton.setText(i);
radiobutton.setId(i);
radiogroup.addView(radiobutton, rg);
}
}
catch(Exception ex)
{
err.setText(ex.toString());
}
}
});
}
}
public void onCreate(捆绑冰柱){
超级冰柱;
//ToDo在此处添加GUI初始化代码
setContentView(R.layout.main);
go=(按钮)findViewById(R.id.go);
否=(EditText)findViewById(R.id.noofradio);
err=(TextView)findViewById(R.id.err);
go.setOnClickListener(新的OnClickListener(){
公共void onClick(视图arg0){
尝试
{
int a=Integer.parseInt(no.getText().toString());
放射组放射组=新放射组(MainActivity.this);
LinearLayout.LayoutParams rg=新的RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_内容,
RadioGroup.LayoutParams.WRAP_内容);
for(int i=0;i
这是我的xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>"
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="RadioButtons"
android:id="@+id/err"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/noofradio">
</EditText>
<Button
android:id="@+id/go"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Buttons">
</Button>
</LinearLayout>
”
android内容资源未找到异常stringresource id 我认为您的xml中有一个错误(我猜是使用未定义的字符串资源)
android内容资源未找到异常stringresource id
我认为您的xml中有一个错误(我猜是使用未定义的字符串资源)对setText()的调用需要字符串资源id。具体地说,
radiobutton.setText(I)
将“I”解释为字符串资源id,而不是您传递的索引。对setText()的调用需要字符串资源id。具体来说,radiobutton.setText(i)
将“i”解释为字符串资源id,而不是您传递的索引。请详细说明出现错误的原因和原因?请将logcat o/p粘贴到此处Android内容资源$not found exception stringresource id..我不知道如何使用logcatat查找您的错误我想您没有在xml中声明视图的id。请粘贴xml文件在这里查看更多查看请详细说明您遇到了什么错误和什么错误?请将logcat o/p粘贴到此处Android内容资源$not found exception stringresource id..我不知道如何使用logcatat查找您的错误我想您没有在xml中声明视图id。请将xml文件粘贴到此处查看更多查看您可以发布布局文件(main.xml),和values/strings.xml会很有帮助,因为它看起来不像xml:)我已经发布了它,但它没有出现??它现在出现了。没有发现任何错误(除了“after>,code highlighting error?)…您可以发布布局文件(main.xml),values/strings.xml会很有帮助,因为它看起来不像一个xml:)我已经发布了它,但它没有出现??它现在出现了。没有看到任何错误(除了“after>,代码突出显示错误…”。。。