-1

嘿,我現在嘗試添加一個DialogFragment片段。它應該開放時,我在一個TextView點擊:從片段打開對話框片段 - FragmentManager出錯

片段:

public class FragmentOneRm extends Fragment { 



@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    myContext = (main_container)this.getActivity(); 

} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { mTextViewMaxWeight.setOnLongClickListener(new View.OnLongClickListener() { 
//other code   
     @Override 
     public boolean onLongClick(View v) { 
      DialogWeightConverter dialog = DialogWeightConverter.newInstance(); 
     // Problem with getFragmentManager() 
      dialog.show(getFragmentManager(), "fragmentDialog"); 

     } 
    }); 


    return view; 

出現以下錯誤:無法解析梅索德秀(android.app.FragmentManager,java.lang.String中)

是的,我知道這個問題已經excist但對我的解決方案沒有工作:/

我DialogFragment:

公共類DialogWeightConverter擴展迪alogFragment {

Context mContext; 

public DialogWeightConverter() { 
    mContext = getActivity(); 
} 


@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    Dialog dialog = builder.create(); 

    return dialog; 
} 

public static DialogWeightConverter newInstance() { 
    DialogWeightConverter f = new DialogWeightConverter(); 
    return f; 
} } 

如果從項目需要更多的代碼,我將它添加

感謝您的幫助和問候

+0

確保您在每個地方使用一種類型的片段,否則這將是一個問題。使用支持片段即v4片段或正常應用片段 – dex

+0

具體問題是什麼? –

回答

1

DialogWeightConverterandroid.support.v4.app.DialogFragment延伸?嘗試使用getActivity().getSupportFragmentManager()