0

我使用Textview作为标题,但没有使用ListView项目行获取所选项目的名称,每当我运行我的应用程序时,第一个listview将菜单显示为标题中的文本,因为我已经在xml中给出,但在第二个活动的标题中我只是将“标题”作为标题而不是选定项目标题,请查看我缺少的地方:-

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);
4

1 回答 1

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);
   }
});
于 2012-10-18T10:21:09.493 回答