[問題] Fragment and DialogFragment

作者: joycece (joycece)   2016-01-14 20:45:57
想請問如何在Fragment上去呼叫Dialogment?
我在網路上看到此程式碼範例, 想實做看看
http://android-developers.blogspot.tw/2012/05/using-dialogfragments.html
但是有段程式一直報錯
private void showEditDialog() {
FragmentManager fm = getSupportFragmentManager();
EditNameDialog editNameDialog = new EditNameDialog();
editNameDialog.show(fm, "fragment_edit_name");
}
如果是照範例上貼上 會出現錯誤
require : android.app.FragmentManager
found: android.support.v4.app.FragmentManager
若依建議改成不報錯的話
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
就會換這行錯誤
editNameDialog.show(fm, "fragment_edit_name");
請問應該怎麼辦?
謝謝
作者: ssccg (23)   2016-01-14 21:12:00
import android.support.v4.app.DialogFragment;要用support library就要整套都用support如果API level在11以上,那就用getFragmentManager()不需要用support版的

Links booklink

Contact Us: admin [ a t ] ucptt.com