2012-10-18 25 views
0

我使用Textview作爲標題,但沒有使用ListView項目行獲取所選項目的名稱,每當我運行我的應用程序第一個列表視圖顯示菜單爲文本在包頭,因爲我在XML給,但在第二個活動的頭,我只是得到「稱號」作爲標題,而不是選定的項目名稱,請參閱我在哪裏丟失: -無法顯示在textview標題中選擇的列表視圖項目標題代替菜單

header.xml

<TextView 
android:id="@+id/actionbar" 
android:layout_width="fill_parent" 
android:layout_height="50dip" 
android:background="@drawable/header" 
android:gravity="center_vertical|center_horizontal" 
android:shadowColor="@android:color/black" 
android:shadowDx="1" 
android:shadowDy="1" 
android:shadowRadius="1" 
android:text="Menu" 
android:textColor="#FFFFFF" 
android:textSize="25dp" 
android:textStyle="bold" /> 

代碼: -

static final String KEY_TITLE = "title"; 
@Override 
    protected void onPostExecute(ArrayList<HashMap<String, String>> result) { 
       TextView lblTitle = (TextView) findViewById(R.id.actionbar); 
       lblTitle.setText(KEY_TITLE); 

回答

0

這個TextView是否直接添加到你的xml中?或者你是否包含它?如果它包括你需要看看那個佈局

TextView lblTitle = (TextView) header.findViewById(R.id.actionbar); 

你也是這樣做從一個異類? UI操作必須始終從UI線程執行。使用這個:

runOnUiThread(new Runnable() { 
    public void run() { 
     TextView lblTitle = (TextView) header.findViewById(R.id.actionbar); 
     lblTitle.setText(KEY_TITLE); 
    } 
}); 
+0

請別人寫一些有用的代碼.....我在等待 – Rashiq

相關問題