2016-07-27 7 views
0

Wie übertrage ich Daten von einer Aktivität in eine andere und setze sie auf die Textansicht?Wie übertrage ich Daten von einer Aktivität in eine andere und setze sie auf die Textansicht?

Das ist meine Absicht:

Intent intent=new Intent(v.getContext(),FinalResultActivity.class); 
     intent.putExtra("questions_count", questions_count); 
     intent.putExtra("questions_correct", questions_correct); 
     intent.putExtra("questions_score", questions_score); 
     intent.putExtra("questions_correct_list", questions_correct_list); 

     v.getContext().startActivity(intent); 

I questions_score auf eine andere Tätigkeit übergeben wollen und es in die Textview gesetzt.

+1

Mögliches Duplikat von [Wie übermittele ich Daten zwischen Aktivitäten auf Android?] (Http://stackoverflow.com/questions/2091465/how-doi-i-pass-data-between-activities-on-android) –

+0

Tonnen Beispiele dafür sind http://stackoverflow.com/questions/18146614/how-to-send-string-from-one-activity-to-another –

Antwort

0

Probieren Sie es

class SecondActvty extends activity{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.second_activity); 

     if (getIntent().getExtras() != null) { 
      textView.setText(getIntent().getExtras().getString("questions_count", "")); 
     } 
    } 

} 
+0

Danke, es hilft. – Shagun

+0

Bitte stimme die Antwort ab, wenn es hilfreich ist. – Andolasoft

0

firstActivity

Intent intent=new Intent(v.getContext(),FinalResultActivity.class); 
    intent.putExtra("questions_count", questions_count); 
    intent.putExtra("questions_correct", questions_correct); 
    intent.putExtra("questions_score", questions_score); 
    intent.putExtra("questions_correct_list", questions_correct_list); 
    startActivity(intent); 
    finish(); 

FinalResultActivity.class

get Wert innerhalb des onCreate wie

Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
    String count = extras.getString("questions_count"); 
    String correct =extras.getString("questions_correct"); 
     textview.setText(count); 
     textview1.setText(correct); 
     } 
Verwandte Themen