[英]Transfer data from one screen to another on android eclipse
Hi am newbie to java and android. 嗨,我是Java和android的新手。
Assume function demo()
from the screenone is going to display some values on Textview
which is on the same screen(screenone). 假设来自screenone的功能demo()
将在同一屏幕(screenone)上的Textview
上显示一些值。
But i need to display that resultant value to the next screen ie.(screen two) 但是我需要在下一个屏幕上显示该结果值。(屏幕二)
public void demo(){
{
.....
.....
}
So i have included these line to 所以我将这些行包括在内
screenoneActivity.java screenoneActivity.java
Intent nextScreen = new Intent(getApplicationContext(), SecondtwoActivity.class);
nextScreen.putExtra("","");
startActivity(nextScreen);
demo();
ScreentwoActivity.java ScreentwoActivity.java
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
TextView txtName = (TextView) findViewById(R.id.textView1);
Intent i = getIntent();
txtName.setText(name);
I did these things so far.I don't know how to do transfer data from demo()
function to the next screen. 到目前为止,我已经做了这些事情,我不知道如何将数据从demo()
函数传输到下一个屏幕。
Can anyone give me clues or ideas to achieve this. 任何人都可以给我线索或想法来实现这一目标。
Thanks a lot!.. 非常感谢!..
You need to send some value into the putExtra methods parameters to be able to get something out of it. 您需要将一些值发送到putExtra方法参数中,以便能够从中获取某些价值。
In your first activity(A): 在您的第一个活动(A)中:
Intent i = new Intent(A.this, B.class);
i.putExtra("someName", variableThatYouNeedToPass);
startActivity(i);
In your second activity(B): 在您的第二项活动(B)中:
Bundle extras = getIntent().getExtras();
int fetchedVariable = extras.getInt("someName");
Write the below code in demo() function: 在demo()函数中编写以下代码:
Intent nextScreen = new Intent(getApplicationContext(), SecondtwoActivity.class);
nextScreen.putExtra("","");
startActivity(nextScreen);
In nextScreen.putExtra("","");
在nextScreen.putExtra("","");
provide some key and value like: 提供一些关键和价值,例如:
nextScreen.putExtra("name","ABC");
Now in SecondActivity, write: 现在在SecondActivity中,编写:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
TextView txtName = (TextView) findViewById(R.id.textView1);
Intent i = getIntent();
Bundle bundle = i.getExtras();
txtName.setText(bundle.getString("name"));
In ScreenoneActivity 在ScreenoneActivity中
Intent act2=new Intent(this,Activity2.class);
act2.putExtra("A",a);
startActivity(act2);
In ScreentwoActivity class 在ScreentwoActivity类中
Intent i = getIntent();
Bundle extras = getIntent().getExtras();
int a = extras.getInt("A");
txtName.setText(a);
in onCreate : 在onCreate中:
Bundle extras = getIntent().getExtras();
String value;
if (extras != null)
{
value= extras.getString("key");
}
https://stackoverflow.com/questions/10752501/how-can-we-go-to-next-page-in-android/10752516#10752516 https://stackoverflow.com/questions/10752501/how-can-we-go-to-next-page-in-android/10752516#10752516
google it is very basic ..... 谷歌这是非常基本的.....
android using intent.... android使用意图...
Vogella Ariticle Vogella Ariticle
in activity 1- 在活动1中
Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");
startActivity(i);
In activity 2 - in onCreate finction 在活动2中-在onCreate函数中
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
// Get data via the key
String value1 = extras.getString(Intent.EXTRA_TEXT);
if (value1 != null) {
// Do something with the data
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.