2016-08-19 1 views
-1

私はフラグメントクラスでgetLayoutInflaterを使用する必要があるが、以下のようなエラーがありますされていますフラグメントレイアウトでgetLayoutInflaterを使用する方法は?

Error:(290, 17) error: method getLayoutInflater in class Fragment cannot be applied to given types; 
required: Bundle 
found: no arguments 
reason: actual and formal argument lists differ in length 

それは私のコードです:

private void initDialog(){ 
    alertDialog = new AlertDialog.Builder(getContext()); 
    view = getLayoutInflater().inflate(R.layout.dialog_layout,null); 
    alertDialog.setView(view); 
    alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      if(add){ 
       add =false; 
       mainListAdapter.addItem(et_country.getText().toString()); 
       dialog.dismiss(); 
      } else { 
       mainListAdapter.mList.set(edit_position,et_country.getText().toString()); 
       mainListAdapter.notifyDataSetChanged(); 
       dialog.dismiss(); 
      } 

     } 
    }); 
    et_country = (EditText)view.findViewById(R.id.et_country); 
} 
+0

使用getActivityを通過する断片であるgetLayoutInflater()膨張(R.layout.dialog_layout、NULL)。 –

答えて

2

は単純に使用します。

LayoutInflater inflater = LayoutInflater.from(getActivity()); 

または

getActivity().getLayoutInflater().inflate(R.layout.dialog_la‌​yout,null); 
0

使用getActivity()あなたは参照も()getActivity()からBuilder(getActivity());

alertDialog = new AlertDialog.Builder(getActivity()); 
    view = getActivity().getLayoutInflater().inflate(R.layout.dialog_layout,null); 
関連する問題