1

I am new to Java and Android and come from PHP background. I am trying to display a list view based on arbitrary data received from a previous activity. This the code that I am using:

String[] chapter_array = getResources().getStringArray(R.array.view_chapter);
setListAdapter(new ArrayAdapter<String>(this, R.layout.view_surah, chapter_array));

How do I change the "view_chapter" in R.array.view_chapter to make it populate the list from the data received from the last activity.

2 Answers 2

1

You probably want to write a custom ListAdapter that pulls the data out of the Intent passed to the new activity (i.e. getIntent().getExtras()) and feed that data into your custom ListAdapter.

The Android developer docs have a good sample on how to write a ListAdapter.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. But the same question still stands. The data received from the last activity changed depends on user selection. So how do i make the R.array.(intent_received) changes based on the selection?
0

Similar to Erich's answer you could simply have the previous activity pass a string in CSV form and do String[] chapter_array = getIntent().getExtras().split(','); or something similar to that

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.