改变方向清除TimePicker [英] Changing orientation clears the TimePicker

查看:134
本文介绍了改变方向清除TimePicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习Android应用开发,我发现了以下问题而尝试不同的活性元素。我有以下的code在我的主要活动

 < TableLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / mainLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>    <的TableRow
        机器人:ID =@ + ID / ROW1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT>        < TimePicker
            机器人:ID =@ + ID / timePicker1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT/>    < /&的TableRow GT;< / TableLayout>

它只是一个TimePicker的活动。我的问题是,每当我改变我的移动设备的方位TimePicker的选择时间变成空白,并在LogCat中生成以下错误。

 保存光标位置2/2超出范围(恢复)文本


解决方案

默认情况下,Android的重新启动你的活动当您更改屏幕方向或更改任何配置。您必须指定(在AndroidManifest.xml中),您wan't处理配置改变自己。然后在你的活动,覆盖 onConfigurationChanged()方法。

更多信息可以在这里找到:的http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

I just started learning Android application development and I noticed the following issue while trying different activity elements. I have the following code in my Main activity

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow
        android:id="@+id/row1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TimePicker
            android:id="@+id/timePicker1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </TableRow>

</TableLayout>

Its an activity with just a TimePicker. My issue is that whenever I change the orientation of my mobile device the hour selection of the TimePicker goes blank and the following error is generated in the LogCat.

Saved cursor position 2/2 out of range for (restored) text

解决方案

By default, Android restarts your Activity when you change your screen orientation or any configuration change. You will have to specify (in your AndroidManifest.xml) that you wan't to handle the configuration change yourself. Then in your activity, override the onConfigurationChanged() method.

More info can be found here: http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

这篇关于改变方向清除TimePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆