-1

こんにちは、JavaとAndroidの初心者です。

screenoneの関数が、同じ画面(screenone)にあるdemo()いくつかの値を表示するとします。Textview

しかし、その結果の値を次の画面に表示する必要があります。(画面2)

public void demo(){
{
 .....
 .....
}

だから私はこれらの行をに含めました

screenoneActivity.java

Intent nextScreen = new Intent(getApplicationContext(), SecondtwoActivity.class);
nextScreen.putExtra("","");
startActivity(nextScreen);
demo();

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);

demo()私はこれまでこれらのことをしました。関数から次の画面にデータを転送する方法がわかりません。

誰かが私にこれを達成するための手がかりやアイデアを与えることができますか?

どうもありがとう!..

4

4 に答える 4

2

putExtraメソッドのパラメーターに値を送信して、そこから何かを取得できるようにする必要があります。

最初のアクティビティ(A):

Intent i = new Intent(A.this, B.class);
i.putExtra("someName", variableThatYouNeedToPass);
startActivity(i);

2番目のアクティビティ(B):

Bundle extras = getIntent().getExtras();
int fetchedVariable = extras.getInt("someName");
于 2012-05-30T05:57:50.043 に答える
1

以下のコードをdemo()関数に記述します。

Intent nextScreen = new Intent(getApplicationContext(), SecondtwoActivity.class);
       nextScreen.putExtra("","");
       startActivity(nextScreen); 

nextScreen.putExtra("","");のようなキーと値を提供します。

nextScreen.putExtra("name","ABC");

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"));
于 2012-05-30T05:59:42.740 に答える
1

ScreenoneActivityで

Intent act2=new Intent(this,Activity2.class);
    act2.putExtra("A",a);
    startActivity(act2);

ScreentwoActivityクラス内

Intent i = getIntent();
Bundle extras = getIntent().getExtras(); 
int a = extras.getInt("A");
txtName.setText(a);
于 2012-05-30T06:08:42.807 に答える
0

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

グーグルそれは非常に基本的です.....

インテントを使用してAndroid...。

Vogella Ariticle

アクティビティ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);

アクティビティ2-onCreatefinctionで

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
}
于 2012-05-30T05:57:23.437 に答える