【问题标题】:Not able to show selected listview item title in textview header in place of Menu无法在文本视图标题中显示选定的列表视图项目标题代替菜单
【发布时间】:2012-10-18 09:59:34
【问题描述】:

我使用 Textview 作为标题,但没有使用 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);

【问题讨论】:

    标签: android android-widget android-listview


    【解决方案1】:

    这个TextView是直接加在你的xml里面的吗?或者你有包括它吗?如果包含,则需要查看该布局

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

    您也是从 asynctask 执行此操作的吗? UI 操作总是必须从 ui 线程执行。使用这个:

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

    【讨论】:

      猜你喜欢
      • 2016-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多