0

I have an array with questions, which is display on the screen. When you click on a item, you go to the anwer. That's all working fine. But the (header)label doesn't display the question, only the app name.

I readed this article. But every time you click on a question, it's a different question, so you can't do it hardcoded. Wen you click on a question a new activity starts. I would be nice if the question(item of the array) is send to the new acitivity.

So this is the listview filled with the items of the array questions: enter image description here

And this is the new activity when you click on a question: enter image description here

The "IDP2013" has to change tot the question you clicked on.

list_data.xml:

<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="Questions"> <item>Where is the exit button?</item> <item>Why cant I launch a rocket?</item> <item>Why cant I hack the other teams?</item> <item>How can I get back to the home screen?</item> <item>test</item> </string-array> <string-array name="Answers"> <item>Right above, click the button and then the last button "exit".</item> <item>Because there is no rocket.</item> <item>Have patience.</item> <item>Left above, click the button. </item> <item>test</item> </string-array> 

AndroidManifest.xml:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.activity.idp2013" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > ... <activity android:name="com.activity.idp2013.SingleListItem" android:label="@array/Questions"> </activity> ... </application> </manifest> 

1 Answer 1

1

Use the intent.putExtra to pass the data to an another activity.

Intent intent = new Intent(this, NewActivity.class); intent.putExtra("questionName", array[selectedPosition]); startActivity(intent); 

then in NewActivity get this string using:-

String questionName = ""; Bundle extras = getIntent().getExtras(); if (extras != null) { this.questionName = extras.getString("questionName"); } 

And set this questionName to setTitle of NewActivity.

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

5 Comments

Isn't the configIntent in the first code block meant to be intent?
It says that it can't find a match. So I have to add questionName to the strings.xml. But then it's useless again, because it isn't variable anymore.
What do u mean can't find a match. it has to.. so long as the string "questionName" is same along with case..can u post code?
"error: Error: No resource found that matches the given name (at 'label' with value '@string/questionName')." Because I changed the label name android:label="@string/questionName">
y r u adding questionName in Strings.xml...you only need to pass it when calling the new intent and use as i posted.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.