Android,我如何获取上一个活动状态?

布阿图

我有一个one.xml文件:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:orientation="vertical"
    android:id="@+id/lineerLayout">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/sp_info"
        android:id="@+id/label_sp_info"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/label_x" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:id="@+id/spx"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/label_y" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="numberDecimal"
        android:id="@+id/spy" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_label_continue"
        android:id="@+id/continue_aligment" />
</LinearLayout>
</ScrollView>

然后我有这样的two.xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/nPointlinearLayout"
>
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/nPointInfo" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/labelnPointX"/>
<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal"
    android:id="@+id/nPointX" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/labelnPointY" />
<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="numberDecimal"
    android:ems="10"
    android:id="@+id/nPointY" />
</LinearLayout>

当我使用充气机单击按钮时,可以在one.xml中添加two.xml。没有问题。但是,当我单击电话后退按钮或退出所有活动,然后重新输入时,添加视图就消失了。我如何获得上一个活动状态?带有所有ID?

这是我要单击按钮的代码。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.one);
    continueAligment=(Button)findViewById(R.id.continue_aligment);
    lineerLayout=(LinearLayout)findViewById(R.id.lineerLayout);
    inflater=getLayoutInflater();
    continueAligment.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            view=inflater.inflate(R.layout.two,lineerLayout,false);
            nPointLineerLayout=(LinearLayout)view.findViewById(
               R.id.nPointlinearLayout);
            lineerLayout.addView(nPointLineerLayout,
            lineerLayout.indexOfChild(continueAligment));
        }
    });
}
Mr_and_Mrs_D

在共享首选项中添加值

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.one);
    continueAligment = (Button) findViewById(R.id.continue_aligment);
    lineerLayout = (LinearLayout) findViewById(R.id.lineerLayout);
    final SharedPreferences sp = PreferenceManager
        .getDefaultSharedPreferences(this);
    inflater = getLayoutInflater();
    if (sp.getBoolean("ADD_TWO", false)) {
        inflateTwo();
    } else continueAligment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            inflateTwo();
            sp.edit().putBoolean("ADD_TWO", true).commit();
        }
    });
}

private void inflateTwo() {
    view = inflater.inflate(R.layout.two, lineerLayout, false);
    nPointLineerLayout = (LinearLayout) view
        .findViewById(R.id.nPointlinearLayout);
    lineerLayout.addView(nPointLineerLayout,
        lineerLayout.indexOfChild(continueAligment));
}

当然,如果您已经添加了两个按钮,则想禁用该按钮-否?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

滚动上一个屏幕后如何获取上一个活动

如何根据我在android中遵循的路径返回上一个活动?

如何从上一个活动中使用onBackPressed永久退出我的Android应用

Android:如何返回上一个活动

如何回到android中的上一个活动?

通过存储上一个活动结果来刷新活动状态Android

当前活动处于暂停状态后,如何转到上一个活动

Android:返回上一个活动

如何返回上一个活动?

如何返回上一个活动

我的Android应用程式有两项活动。在我的第二个活动中,我有一个按钮用于获取上一个活动的屏幕截图

如何在Android中关闭活动并返回上一个活动

如何在android中关闭当前活动返回上一个活动?

每次我开始上一个活动时,Android 应用程序都会崩溃

如何完成一项活动但我不想去上一个活动(转到另一个活动)

回到android中的上一个活动

Android退出上一个活动

Android后退按钮不会返回上一个活动

Android工具栏:如果按下向后箭头,如何返回上一个活动

如何在Android中的上一个活动中接收数据

如何在Android的react-native中重新设置为上一个活动?

android如何在点击通知时打开上一个活动

按下后退按钮后,从本机(android)活动转到上一个场景的刷新状态

最近屏幕后如何返回上一个活动

如何完成当前活动并返回上一个片段?

如何防止回到上一个活动?

如何使用恢复按钮进行上一个活动?

如何在react-native-webview中保持上一个Web会话处于活动状态?

跳至下一个活动时如何销毁上一个活动