getSupportFragmentManager() is undefined

后端 未结 8 1193
生来不讨喜
生来不讨喜 2020-12-29 00:50

I\'m getting the following error: \"The method getSupportFragmentManager() is undefined for the type new View.OnClickListener(){}\" in my fragment

相关标签:
8条回答
  • 2020-12-29 01:47

    Try changing your code to this:

    public class ObstetricsFragment1 extends SherlockFragment{
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState)
    {
        //Fragment Layout
        View view = inflater.inflate(R.layout.obstetricsfragment1, container, false);
    
        Button mPickLMPDate = (Button) view.findViewById(R.id.pickLMPDate);
    
        mPickLMPDate.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                LMPDatePickerDialogFragment d = LMPDatePickerDialogFragment.newInstance();
                FragmentManager fm = ObstetricsFragment1.this.getSherlockActivity().getSupportFragmentManager();
                d.show(fm, "dialog");
            }
    
        });
    
        return view;
    }
    
    0 讨论(0)
  • 2020-12-29 01:50

    I had a similar problem loading a lesson project (https://developer.android.com/training/multiple-threads).

    To resolve, I had to add an external jar (sdk/extras/android/support/v4/android-support-v4.jar).

    Hope this helps.

    0 讨论(0)
提交回复
热议问题