2013-03-29 47 views
5

我有一个偏好屏幕(responder_generic.xml)(2.3.3版本)findViewById如下返回null偏好布局

addPreferencesFromResource(R.xml.responder_generic); 

和我的布局= preference_header_switch_item_responder看起来如下:

<?xml version="1.0" encoding="utf-8"?> 
<!-- Layout of a header item in PreferenceActivity. --> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="33dp" 
    android:gravity="center_vertical" 
    android:minHeight="33dp" 
    android:id="@+id/preference_header_switch_item_responder" 
    style="?android:attr/listSeparatorTextViewStyle" > 

    <RelativeLayout 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     android:layout_weight="1" > 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="marquee" 
      android:fadingEdge="horizontal" 
      android:singleLine="true" 
      android:text="@string/auto_responder" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/summary" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@android:id/title" 
      android:ellipsize="end" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 
    </RelativeLayout> 

    <include layout="@layout/compound_button" /> 

</LinearLayout> 

现在,我有化合物按钮d分别在layout文件夹和layout/v-14 efined如下:

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > 

<CheckBox 
    android:id="@+id/switchWidget" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:clickable="true" 
    android:focusable="false" 
    android:padding="8dip" 
    android:layout_marginRight="14dip" /> 

</merge> 

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <Switch 
     android:id="@+id/switchWidget" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:clickable="true" 
     android:focusable="false" 
     android:padding="8dip" 
     android:layout_marginRight="14dip"/> 

</merge> 

在​​的方法,我想找到使用findViewById(R.id.switchWidget)但它总是返回null,则此复选框/在运行时开关。

任何想法可能是什么原因?

回答