问题描述
我正在为Android编写电话拨号器应用程序.我为键盘创建了一个布局,其中包含一个TextView和10个按钮.按钮是10位数字(从0到9)的键,而TextView是根据所按的键显示数字的键.
I am writing a phone dialer app for android. I created a layout for keypad, which contains a TextView and 10 buttons. Buttons are as keys for 10 digits(0 to 9) and TextView is for displaying the number according to keys pressed.
在我的应用程序中,我将按下的每个按钮的文本("0"或"1"等)附加到TextView中.如果我按按钮1、2、3 ,则TextView上的文本为123 .问题是,让屏幕处于横向模式,TextView包含123(如果我将其打开),在纵向模式下TextView上没有文本.
In my app, i am appending the text ("0" or "1", etc.) to the TextView for each button pressed. If i pressed the buttons 1, 2, 3 then the text on TextView is 123.The problem is, let's take the screen is in landscape mode and TextView contains 123, if i turn it, in portrait mode no text on TextView.
请帮助我.
推荐答案
请检查方向更改,在调用create方法时,这要求再次创建所有视图,因此您需要使用以下方法之一:
Please check on orientation change, on create method is called, which requires all the views to be created again, so you need to use one of the following methods:
- 使用onSavedInstance方法并将组件/视图的状态保存到捆绑包中.
-
只需在清单文件中的活动标签android:configChanges ="keyboardHidden | orientation"中使用以下标记true.如下所示:
- use onSavedInstance method and save the states of components/views to bundle.
Just use following flag true in your manifest file in activity tag android:configChanges="keyboardHidden|orientation". like below:
<activity android:name=".SampleActivity" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation">
...
</activity>
这篇关于设备旋转时TextView的文本消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!