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>
Community
  • 1
  • 1
Lutske
  • 117
  • 3
  • 17

1 Answers1

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.

bakriOnFire
  • 2,685
  • 1
  • 15
  • 27
  • Isn't the configIntent in the first code block meant to be intent? – Lutske May 06 '13 at 10:12
  • 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. – Lutske May 06 '13 at 10:29
  • 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? – bakriOnFire May 06 '13 at 10:37
  • "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"> – Lutske May 06 '13 at 10:39
  • y r u adding questionName in Strings.xml...you only need to pass it when calling the new intent and use as i posted. – bakriOnFire May 06 '13 at 10:43