2011-01-25 10 views
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> 
+0

can U PLSでエラーが発生し、エラーが発生しますか?pls logcat o/pここに貼り付けます –

+0

android content resource $見つからないexception stringresource id ..i logcatを使用する方法を知らない –

+0

ur erro ithinkを見ています。xml.plsのxml.plsにurビューのIDを宣言していません。詳しくはこちら –

答えて

1

アンドロイドコンテンツリソース$が見つかりません例外文字列リソースID

私はあなたがhだと思いますあなたのxmlにエラーがあります(まあ、未定義の文字列リソースを使用していると思います)

+0

どうすればいいですか? –

+0

あなたのレイアウトファイル(main.xml)を投稿することができ、値/ strings.xmlも役に立ちます – note173

+0

+1無駄に直面したときに親切です。 – Qberticus

0

setText()を呼び出すと、文字列リソースIDが必要です。具体的には、radiobutton.setText(i)は、文字列リソースIDと渡すインデックスを 'i'と解釈しています。

関連する問題