2016-03-19 9 views
0

問題があります。私はナビゲーション・ドロワを追加することにしましたが、アプリに単純な電卓を作成しようとすると、ボタンやテキストビューを参照することさえできません。これは私が計算機を作成したい活動のためのコードです。また、マップアクティビティとSQLiteデータベースを追加する必要があります。ナビゲーションドロワーに電卓を追加する

public class Calculator_main extends Fragment { 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     View rootview = inflater.inflate(R.layout.calculator, container, false); 
     return rootview; 
    } 
} 

答えて

0

使用rootView断片で参照するときにあなたの項目を見つけるために:

public class Calculator_main extends Fragment { 

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View rootview = inflater.inflate(R.layout.calculator, container, false); 

    //Notice the TextView being referenced with rootView in front of the findViewById statement 
    TextView namefield = (TextView) rootView.findViewById(R.id.namefield); 

    return rootview; 
    } 
} 

このアプリは、あなたのフラグメントの内の項目を参照することができる唯一の方法であるとして、あなたは、フラグメントを使用するときにこれを実行する必要がありますXMLビュー

これはアクティビティでは必須ではなく、フラグメント内での参照方法と混同しないでください。