I want to pass different string values to another activity based upon the selection of the item in the list. This should do be done in only one textview. As I am unable to find as it's showing that the textview id is already assigned to another one. How can I pass multiple strings to a single textview of another activity?
Here is the code:
In Main Activity:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int i, long id) {
switch (i){
case 0:
Intent intent = new Intent(MainActivity.this, intent_activity.class);
intent.putExtra("first", FourDos);
startActivity(intent);
break;
case 1:
Intent intent1 = new Intent(MainActivity.this, intent_activity.class);
intent1.putExtra("second", FourGL);
startActivity(intent1);
break;
case 2:
Intent intent2 = new Intent(MainActivity.this, intent_activity.class);
intent2.putExtra("second", FourTest);
startActivity(intent2);
break;
}
}
});
listView.setAdapter(itemsAdapter);
In another activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent_activity);
Intent intent= getIntent();
String message = intent.getStringExtra("first");
TextView text = (TextView) findViewById(R.id.intent_text);
text.setText(message);
Intent intent1= getIntent();
String message1 = intent1.getStringExtra("second");
TextView text1 = (TextView) findViewById(R.id.intent_text);
text1.setText(message1);
Intent intent2= getIntent();
String message2 = intent2.getStringExtra("third");
TextView text2 = (TextView) findViewById(R.id.intent_text);
text2.setText(message2);
}
Here are the screenshots