0

I'm starting to learn a bit about android programming and watch plenty of guides/tutorials but there's one question none of the guides answer. I have a radio group of two buttons, simply like this(in the xml):

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="button1" />

    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button2" />
</RadioGroup>

The thing is that i want to show different textviews and different edittexts depending on what radio button is clicked, does anybody know where i can find a good example about this or might even wanna make an example yourself?

Thanks

4

2 回答 2

0

您可以简单地将 type1 的 textview 与一些父视图(如 LinearLayout 等)包装起来,以用于其他 textview 的类型。
不仅仅是 onCheckedChanged(RadioGroup arg0, int checkedId) 显示和隐藏包装视图。

于 2013-01-11T17:42:24.487 回答
0

最简单的方法是将所有内容添加到主视图中。然后,根据单击的内容,将您不想看到的所有项目的可见性设置为 View.GONE,将您不想看到的项目的可见性设置为 View.INVISIBLE。或者,如果您有更复杂的东西并且两个视图不共享很多变量,那么将它们实现为片段可能是有意义的。

于 2013-01-11T17:42:59.333 回答