1
我有一個EditText上取決於編輯的文本提供的電話號碼我要創建一個單選按鈕,但即時得到錯誤,這是我的代碼單選框動態
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());
}
}
});
}
}
這是我的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>
cAN U PLS詳細說明了您是否收到錯誤以及出現什麼錯誤?請在此處粘貼logcat o/p – 2011-01-25 06:27:49
沒有發現異常字符串資源ID ..我不知道如何使用logcat – 2011-01-25 06:33:44