2013-03-14 81 views
0

确定方法的ShowDialog(INT,束)从活动类型已过时。所以我已经改变了我的timePicker到fragmentDialog因为fragmentDialog编写这是很容易:AlertDialog到DialogFragment

new TimePickerDialog(getActivity(),_listener, _hour, _minute,dateFormat); 

但是,我怎么能重拍我的这种类型的对话框fragmentDialog?

AlertDialog.Builder 
     .setIcon() 
     .setTitle() 
     .setPositiveButton() 
     .setSingleChoiceItems(new CharSequence[]{"Visual","Audio","Both"},2,null) 

谢谢。

+0

无法理解:'我怎么能翻拍fragmentDialog很多我这种类型的对话与相同的布局'你要显示一个单choiced AlertDialog?在DialogFragmnet中? – 2013-03-14 19:04:51

+0

我改变了我的问题。希望这更清楚。 – vlkpo 2013-03-14 19:08:15

+0

目前尚不清楚。我知道你不想使用'showDialog'并且想要使用'AlertDialog.Builder .setIcon() .setTitle() .setPositiveButton() .setSingleChoiceItems(new CharSequence [] {“Visual “,”Audio“,”Both“},2,null)'在DialogFragment'中,对吗? – 2013-03-14 19:12:09

回答

0

如果我正确理解你,你想重用你的AlerDialog,所以你可以定义它一次,并在片段/活动中的不同位置使用。

从Android文档AlertDialog android.app.AlertDialog.Builder.create()Creates a AlertDialog with the arguments supplied to this builder. It does not show() the dialog. This allows the user to do any extra processing before displaying the dialog. Use show() if you don't have any other processing to do and want this to be created and displayed. 所以:

//declare inside your fragment class 
private AlertDialog welcomeDialog; 

//Inisde onCreate paste the following code so your dialoge is just created but not shown 
      welcomeDialog = new AlertDialog.Builder(this) 
       .setIcon(android.R.drawable.ic_dialog_alert) 
       .setTitle(
         getResources().getString(R.string.first_run_title)) 
       .setMessage(
         getResources().getString(R.string.first_run_desc)) 
       .setPositiveButton(R.string.ok, 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, 
            int which) { 
           dialog.dismiss(); 
          } 
         }).create(); 

//Wherever in your code you need to display the dialog,just use this piece of code: 
welcomeDialog.show(); 

//and finally to do the cleanup: 
    @Override 
protected void onStop() { 
    super.onStop(); 
    if (welcomeDialog != null) 
     welcomeDialog.dismiss();} 
+0

这个人没有回应,所以我没有回答他的问题 – 2013-03-17 17:34:04

+0

请回答,因为它可能对我和其他人有帮助 – 2013-03-19 19:03:37

+0

你试过@加力燃烧的回答吗? – 2013-03-19 19:53:16

相关问题