Радиобутон динамически

1

У меня есть edittext в зависимости от числа, указанного в текстовом редакторе. Мне нужно создать радиообъем, но im get error это мой код.

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
    МОЖЕТЕ УЗНАТЬ PLS, где вы получаете ошибку и какую ошибку? Пожалуйста, вставьте logcat o / p здесь
  • 0
    ресурс контента для Android $ не найден исключение stringresource id .. я не знаю, как использовать logcat
Показать ещё 1 комментарий
Теги:

2 ответа

1

ресурс контента для Android $не найден исключение stringresource id

Я думаю, что у вас есть ошибка в вашем xml (ну, я полагаю, используя undefined),

  • 0
    как я могу это сделать???
  • 0
    Вы можете опубликовать свой файл макета (main.xml), и вам также будет полезен values / strings.xml
Показать ещё 6 комментариев
0

Вызов setText() ожидает идентификатор строкового ресурса. В частности, radiobutton.setText(i) интерпретирует "i" как идентификатор строкового ресурса по сравнению с индексом, который вы передаете.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню