I have been searching other stackoverflow questions and also looking through the android developer guide but I have not found an solution yet.. In my program I ask the user to enter in a homework assignment that they have just received. From there I take that message and I print it on a new screen. What I want to be able to do is save the previous messages entered in and print those out each time along with the new message. What I am having trouble is printing more than one message at a time. I used setContentView but it only prints one message. Does anyone have any advice? I have posted my code at the bottom:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
getActionBar().setDisplayHomeAsUpEnabled(true);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
saveHomework(message);
// Set the text view as the activity layout
setContentView(textView);
}
public void saveHomework(String message)
{
String message2 = message;
TextView textView2 = new TextView(this);
textView2.setTextSize(40);
textView2.setText(message2);
setContentView(textView2);
}
Well, apparently you should preserve all previously entered messages in some place.
Your options:
Then, whereever you want to show the messages you should read them from where you have them saved and pass all together to setText(messages_list) call.