2013-05-06 58 views
0

我有一個問題的數組,它顯示在屏幕上。當你點擊一個物品時,你會轉向一個物品。這一切工作正常。但(標題)標籤不顯示問題,只顯示應用程序名稱。android更改labelname與數組的項目

我試過this文章。但是每次你點擊一個問題,這是一個不同的問題,所以你不能硬編碼。溫你點擊一個新的活動開始的問題。如果問題(數組的項目)發送到新的活動,我會很好。

因此,這是一個充滿的陣列問題的項目列表視圖: enter image description here

當你點擊一個問題,這是新的活動: enter image description here

的「IDP2013」​​必須改變總結您點擊的問題。

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

使用intent.putExtra將數據傳遞到另一個活動。

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

然後NewActivity獲得使用該字符串: -

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

這questionName設置爲NewActivity的的setTitle。

+0

第一個代碼塊中的configIntent是不是意圖? – Lutske 2013-05-06 10:12:26

+0

是的,我的壞,更新帖子 – bakriOnFire 2013-05-06 10:14:11

+0

它說它找不到匹配。所以我必須添加questionName到strings.xml。但是它再次無用,因爲它不再是可變的。 – Lutske 2013-05-06 10:29:38