2011-10-31 4 views
3

可能性の重複:私は現在、次のように動作しているアプリケーション働いている
How do I save an Android application's state?のAndroidでのアクティビティを保存

: を私は2 EDITTEXTを使用しています私はそれを入力するいくつかの値がありますし、私はボタンを押したときに それは次のページまたはアクティビティに移動しますが、私はここに私がedittextの値を見つけることはできません。 。 あなたの中に提供さbundelの編集中に保存

public class TestsampleActivity extends Activity 
{ 
     Button b1,b2; 
     TextView t1; 
     EditText e1; 

     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 

      b1= (Button)findViewById(R.id.btn1); 
      b2= (Button)findViewById(R.id.btn2); 
      t1=(TextView)findViewById(R.id.tv1); 
      e1=(EditText)findViewById(R.id.et1); 


      b1.setOnClickListener(new Button.OnClickListener() 
      { 
       public void onClick (View v){ add(); } 
      }); 

      b2.setOnClickListener(new Button.OnClickListener() 
      { 
       public void onClick (View v){ del(); } 
      }); 
     } 
     public void add() 
     { 
      String s1= e1.getText().toString(); 
      Intent intent=new Intent(this,next.class); 
      intent.putExtra("name",s1); 
      startActivity(intent); 


      /* String s1= e1.getText().toString(); 
      //t1.append(s1); 
      t1.setText(s1); 
      */ 
     } 
     public void del() 
     {    
      e1.setText(""); 
      t1.setText(""); 
     } 
} 

答えて

1

新しいアクティビティをロードする前にデータを保存するには、onSaveInstanceState(Bundle b)をオーバーライドする必要があります。また

あなたがonRestoreInstanceStateをオーバーライドして戻って値を取得する復元する必要があります...

することができますここではそれ自体の詳細情報:

Saving Android Activity state using Save Instance State

または

http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)

1

....これは私のコードである

....事前に おかげで...私はコードを教えてくださいテキストonSaveInsanceState()メソッド。次に、onRestoreInstanceState()メソッドで、保存した値を使用して、編集テキストのテキストを復元します。

1

直前のアクティビティに戻る: follを使用する方法:

Intent intent_obj=new Intent(); 
String id = intent_obj.getStringExtra("id"); 
e1.setText(id); 

これは動作します.... !!!

+0

助けてくれてありがとう... –

+0

こんにちは、私のAnsの左側にある上の矢印を押すよりも機能する場合:) –

関連する問題