从一个活动传递到另一个数据在Android中 [英] Passing data from one activity to another in Android

查看:129
本文介绍了从一个活动传递到另一个数据在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/3510649/how-to-pass-a-value-from-one-activity-to-another-in-android">How从一个活动将值传递给另一个机器人?

我有一个标题(从ApiDemos list6例子)名单,他们的尸体(内容)的活动。我有一个活动,在这里我想补充的说明。当我点击添加按钮,我希望我的笔记的标题出现在列表中。同样的,身体。问题是,在名单的活动有两个String []数组与predefined硬codeD标题和机构。我应该怎么做才能够与内容,而无需这些硬件codeD值添加自己的新游戏? 我知道我必须使用意图与startActivityForResult,但是这可能是我所知道的......

I have an activity with a list of titles and their bodies(content) (list6 example from ApiDemos). And I have an activity, where I add a note. When I click on "Add" button, I want the title of my note to appear on the list. Same with body. The problem is, that in List activity there are two String[] arrays with predefined hard-coded titles and bodies. What should I do to be able to add my own new titles with a content instead of having these hard-coded values? I know I must use intents with startActivityForResult, but that's probably all I know...

推荐答案

您有两个选项:

此方式,可以使用它的情况相同,从与添加按钮的活动,并修改列表视图为:

This way you can use the same instances of it from the activity with add button and modify the listview as:

FirstActivity.listTitlesArrayList.add(listTitleString);
FirstActivity.listDescriptionArraylist.add(listDescriptionString);//this is probably your note
FirstActivity.listView.invalidateViews();

2),如果你想使用意图:

而要去ListActivity通数据通过。

2)if you want to use intents:

while going to the ListActivity pass data by..

intent.putExtra("Title", listTitleString);
intent.putExtra("Content", listDescriptionString);
startActivity(intent);

和恢复它的第二个活动使用的:

and to recover it in second activity use:

title= getIntent().getExtras().getString("Title");

...等..

...and so on..

这篇关于从一个活动传递到另一个数据在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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