Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:谷歌地图搜索后的奇怪行为_Android_Google Maps - Fatal编程技术网

Android 安卓:谷歌地图搜索后的奇怪行为

Android 安卓:谷歌地图搜索后的奇怪行为,android,google-maps,Android,Google Maps,一开始,应用程序看起来像“标题1内容1”;标题2内容2;标题3内容3’。 当你按下“转到谷歌地图”按钮时,这个应用程序打开并搜索“朝鲜”。当你们返回时,应用程序变成了“标题1内容3”;标题2内容3;标题3内容3'(所有内容均为3)!为什么?至少在安卓4.0.4(华为荣誉官方)上发生 如您所见,我使用了带有LinearLayout的ScrollView,并在其中添加了一个视图,如item.xml所述 AndroidManifest.xml <?xml version="1.0" encodi

一开始,应用程序看起来像“标题1内容1”;标题2内容2;标题3内容3’。 当你按下“转到谷歌地图”按钮时,这个应用程序打开并搜索“朝鲜”。当你们返回时,应用程序变成了“标题1内容3”;标题2内容3;标题3内容3'(所有内容均为3)!为什么?至少在安卓4.0.4(华为荣誉官方)上发生

如您所见,我使用了带有LinearLayout的ScrollView,并在其中添加了一个视图,如item.xml所述

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.HelloWorld"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name="MyActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Go to Google Maps"
            android:id="@+id/button" android:onClick="openMaps"/>
    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/scrollView">
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:longClickable="false" android:id="@+id/linearLayout">
        </LinearLayout>
    </ScrollView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Header"
            android:id="@+id/header" android:layout_gravity="left|center_vertical" android:textStyle="bold"
            android:layout_marginLeft="5dp"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Content"
            android:id="@+id/content" android:layout_gravity="left|center_vertical" android:layout_marginLeft="10dp"
            android:textIsSelectable="true"/>
</LinearLayout>
main.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.HelloWorld"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name="MyActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Go to Google Maps"
            android:id="@+id/button" android:onClick="openMaps"/>
    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/scrollView">
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:longClickable="false" android:id="@+id/linearLayout">
        </LinearLayout>
    </ScrollView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Header"
            android:id="@+id/header" android:layout_gravity="left|center_vertical" android:textStyle="bold"
            android:layout_marginLeft="5dp"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Content"
            android:id="@+id/content" android:layout_gravity="left|center_vertical" android:layout_marginLeft="10dp"
            android:textIsSelectable="true"/>
</LinearLayout>

item.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.HelloWorld"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name="MyActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Go to Google Maps"
            android:id="@+id/button" android:onClick="openMaps"/>
    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/scrollView">
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:longClickable="false" android:id="@+id/linearLayout">
        </LinearLayout>
    </ScrollView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Header"
            android:id="@+id/header" android:layout_gravity="left|center_vertical" android:textStyle="bold"
            android:layout_marginLeft="5dp"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Content"
            android:id="@+id/content" android:layout_gravity="left|center_vertical" android:layout_marginLeft="10dp"
            android:textIsSelectable="true"/>
</LinearLayout>


很难说出代码中列出的内容。有一种需要查看活动回调,以查看活动的状态是如何恢复的,以及当您说转到Google Maps时,它将去哪里。我从经验中知道,当您在ScrollView中使用自己的ListView时,创建一个可打包的数据对象来保存对象的状态,以及当重新创建活动或(返回到前面)将视图的状态恢复到您特别希望的状态时,通常是一种良好的做法。如果您使用的是活动而不是片段,则可以使用onCreate()和onSavedInstanceState()回调来完成此操作。如果您在那里提供更多信息,我可以提供更多帮助。

我在这个项目中没有更具影响力的代码。是的,我使用活动。