【问题标题】:how to move data's from one page to the other in Android如何在Android中将数据从一页移动到另一页
【发布时间】:2011-07-21 00:36:55
【问题描述】:

嗨,在我的应用程序中,我放置了两个编辑框和确定按钮。在编辑框中,我得到了名字和第二个名字等值。

现在我想做以下过程 1. 当我点击 OK 按钮时,我移动到新页面,在这里我想显示在第一页的编辑框中输入的数据。

2.在第二页的标题栏中,我要显示在第一个编辑框中输入的数据,即输入的名字必须是第二页的标题。

如何做到这一点请帮助我

【问题讨论】:

  • 当你说“新页面”时,你的意思是开始一个新的活动吗?

标签: java android android-edittext page-title


【解决方案1】:

将确定按钮设置为具有 OnClickListener

public void onCreate(Bundle savedInstanceState) {
View okButton = findViewById(R.id.okButtonImg); //assume you are using custom img for OK
okButton.setOnClickListener(okButtonListener);
}

在 Click Listener 中调用 Intent。 在 Intent 中,您可以使用“putExtra”传递信息

        private OnClickListener okButtonListener = new OnClickListener() {

            public void onClick(View v) {
            Intent secondPageIntent = new Intent(getBaseContext(), SecondPage.class);
            secondPageIntent.putExtra("PASSVALUE","ANY  STRING HERE");
            startActivity(secondPageIntent);

            }
     };

在第二页使用 getExtras("PASSVALUE") 检索您传递的数据

查看这篇文章了解更多详情 http://mylifewithandroid.blogspot.com/2007/12/playing-with-intents.html

【讨论】:

  • 不要使用getBaseContext()。只需使用this。在this 是内部类实例的地方(例如,上面的OnClickListener),使用Java 外部类作用域(例如,MyActivity.this)来获得正确的this 对象。
【解决方案2】:

答案-1)

为此,您需要传递意图中的值以及您在另一个活动中获得的值。

Intent i = new Intent(YourCurrentActivity.this,YourCallingActivity.this);
i.putExtra("key", YourValueToPassAnotherActivity);
startActivity(i);

现在您可以使用 bundle 在您的调用活动中获取此值。

Bundle b = getIntent().getExtras();
b.getString("key");

答案-2)

为此,您需要创建自定义标题栏。 这可能对你有帮助

http://oo-androidnews.blogspot.com/2010/03/android-how-to-add-custom-title-bar.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多