2016-12-26 6 views
0

フラグメントをホストするためのアクティビティを取得しようとしていますが、findViewById()によってウィジェットにアクセスしようとするとフラグメントのビューを膨張させた後、nullを返します。だからこの場合、mBillTitleは常にnullですが、私は何が欠けているのか分かりません。AndroidのフラグメントfindViewByIdは、膨らんだ後にnullを返します。

<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:idに変更android:textです。

+0

すると仮定。ずいぶんありがとう –

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

すごいすっごい、私は盲目だ

android:id="@+id/bill_title" 
関連する問題