在方向改变RadioGroup中的行为 [英] radiogroup behavior on orientation change
问题描述
我希望有人能帮助我理解这是怎么回事就在Android RadioGroup中和onCheckedChanged回调时的方向变化。
I am hoping that someone can help me understand what's going on with respect to an Android radiogroup and the onCheckedChanged callbacks when the orientation changes.
我有三个单选按钮单选按钮组。第二个按钮被定义为通过设置检查属性为true默认。我对无线电集团的XML如下:
I have a radio group with three radio buttons. The second button is defined as the default by setting the checked attribute to true. My xml for the radio group is as follows:
<RadioGroup
android:id="@+id/rgReportRange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/One" />
<RadioButton
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/Two" />
<RadioButton
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Three" />
</RadioGroup>
该RadioGroup中有一个onCheckedChangedListener。当方向变化时,onCheckedChangedListener是基于方向变化之前选择了哪个按钮上被称为回不同。
The RadioGroup has an onCheckedChangedListener. When the orientation changes, the onCheckedChangedListener is being called back differently based on which button is selected before the orientation change.
如果选择按钮1,我看到一次回调以该onCheckedChanged法checkedID等于BUTTON1。
If button1 is selected, I see one callback to the onCheckedChanged method with checkedID equal to button1.
如果选择按钮2,我看不出回调至onCheckedChanged方法。
If button2 is selected, I see no callback to the onCheckedChanged method.
如果选择按钮3,我看到两个回调到onCheckedChanged方法。第一个回调checkedID等于BUTTON2。第二个回调checkedID等于按钮3。
If button3 is selected, I see two callbacks to the onCheckedChanged method. The first callback has checkedID equal to button2. The second callback has checkedID equal to button3.
我不理解在第一和第三例之间的行为的差异。在这两个,还有比选择了默认的单选按钮。
I don't understand the difference in behavior between the first and third cases. In both, there is a radio button other than the default selected.
推荐答案
打开manifest.xml文件,并在活动修改&LT;>标签:
open your manifest.xml file and modify in Activity<> tag :
<activity
android:configChanges="keyboardHidden|orientation"></activity>
在此之后检查结果是::)
after this check your result : :)
这篇关于在方向改变RadioGroup中的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!