2013-05-06 57 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