2016-12-26 67 views
0

我試圖讓活動舉辦一個片段,但膨脹的片段來看,當我嘗試通過findViewById()來訪問任何小部件後,就返回null後空。所以在這種情況下,mBillTitle總是空,我不知道我失蹤了什麼?Android的碎片findViewById返回充氣查看

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="@+id/bill_title" 
     android:textSize="24dp" 
     android:gravity="left"/> 

    .... 

</LinearLayout> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@+id/bill_detail_title" 
    android:textSize="20dp" 
    android:paddingTop="5dp"/> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:paddingTop="5dp"> 

    .... 
</LinearLayout> 

... 

</LinearLayout> 

這是片段代碼

@Override 
public void onCreate(Bundle savedInstanceBundle) { 
    super.onCreate(savedInstanceBundle); 
    mBill = new Bill(); 
} 

@Override 
public View onCreateView(
     LayoutInflater inflater, 
     ViewGroup parent, 
     Bundle savedInstanceBundle) { 

    View view = inflater.inflate(R.layout.bill_details, parent, false); 
    mBillTitle = (TextView) view.findViewById(R.id.bill_title); 
    mBillTitle.setText(mBill.getmShortTitle()); 
    ... 
    return view; 
} 

回答

0

變化android:textandroid:id

+0

OMG哇,我瞎了。非常感謝你 –

1
android:text="@+id/bill_title" 

假設是

android:id="@+id/bill_title"