DialogFragmentはstaticにする必要がある。
public class SampleFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref); PreferenceScreen pref1 = (PreferenceScreen) findPreference("prefkey"); pref1.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { //ダイアログを表示 DialogFragment fragment = new SampleDialogFragment(); Bundle bundle = new Bundle(); bundle.putInt("type", 0); fragment.setArguments(bundle); FragmentTransaction ft = getFragmentManager().beginTransaction(); fragment.show(ft, "dialog"); return false; } }); } public static class SampleDialogFragment extends DialogFragment { public static DBdialogFragment newInstance(String title, String message) { SampleDialogFragmentt frag = new SampleDialogFragment(); Bundle bundle = new Bundle(); bundle.putInt("type", 0); frag.setArguments(bundle); return frag; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final int type = getArguments().getInt("type"); //処理 } } }
0 件のコメント:
コメントを投稿