title.xml是:
<TextView android:textSize="18.0sp" android:textColor="@color/white" android:gravity="center" android:id="@id/titlebar" android:background="@drawable/title_bg" android:layout_width="fill_parent" android:layout_height="38.0dip"
  xmlns:android="http://schemas.android.com/apk/res/android" android:text="@string/test"/>
main.xml有:
<include android:id="@id/title" layout="@layout/title" />
我在main.java下
TextView tvtitle = (TextView) getLayoutInflater().inflate(R.layout.title, null).findViewById(R.id.titlebar);
tvtitle.setText("搜索");为什么tvtitle输出还是"test",而不是"搜索"? 新手求解答

解决方案 »

  1.   

    因为你这里重新inflate了TextView,所以你这里得到的TextView不是属于main.xml中的TextView控件,所以当然不会对main.xml布局产生任何影响,你应该这样改:TextView tvtitle = (TextView)findViewById(R.id.titlebar);
    tvtitle.setText("搜索");你试试我上面写给你的代码
      

  2.   

    我使用了include,包含的R.id.titlebar控件。
    假如直接在main.java下(TextView)findViewById(R.id.titlebar);
    取到的textview,是null。
      

  3.   

    你inflate main.xml布局是什么啊
    总之是这样调用的TextView tvtitle = (TextView)findViewById(R.id.titlebar);//假如main.xml是当前的View,则可以省略
    否则TextView tvtitle=(TextView)mainView.findViewById(R.id.titlebar);
    tvtitle.setText("搜索");