2014-03-29 139 views
0

我試圖在片段內創建DatePicker並返回錯誤方法getSupportFragmentManager()未定義類型CadastroModoVoo。哪裏不對?方法getSupportFragmentManager()未定義爲類型CadastroModoVoo

XML:

<Button android:id="@+id/selectHora3Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:onClick="selectHora3" 
     android:text="Hora" /> 

類:

public class CadastroModoVoo extends Fragment { 
    private FragmentActivity context; 


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

     cadastro_modo_voo = inflater.inflate(R.layout.cadastro_modo_voo, container, false); 
     context = getActivity(); 



     @TargetApi(Build.VERSION_CODES.HONEYCOMB) 
     @SuppressLint({ "ValidFragment", "NewApi" }) 
     public void selectHora3(View view) { 
      qual = 3; 
      DialogFragment newFragment = new SelectTimeFragment(); 
      newFragment.show(getSupportFragmentManager(), "TimePicker"); -----> error 
    } 

回答

0

調用它像context.getSupportFragmentManager()您的上下文變量。 Reference

0

這裏的問題是,的確,類Fragment沒有名爲getSupportFragmentManager()的方法。該方法只在FragmentActivity中。

對於android.support.v4.app.Fragments我認爲調用的正確方法是getChildFragmentManager()。

編輯:現在我正在閱讀roarster的答案,我不確定哪個FragmentManager實際上需要您的DialogFragment - 由getChildFragmentManager返回的或返回的是context.getSupportFragmentManager()...無法嘗試它此刻出...

相關問題