【问题标题】:Non progress dialoge or Alert message be showed in my fragement非进度对话框或警报消息显示在我的片段中
【发布时间】:2012-06-17 13:48:03
【问题描述】:

我有一个扩展 FragmentActivity 的类,我将片段添加到布局中,如下所示

public class maincontrolActivity extends FragmentActivity  {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maincontrol);

                  oUnit fragment = new  oUnit();
                  fragmentTransaction.add(R.id.mainLayout,fragment, "MY_FRAG");
                  fragmentTransaction.commit();

}


}

Ounit 看起来像

public class oUnit  extends Fragment {
         View view = inflater.inflate(
                R.layout.chemounit,
                container,
                false);

/////我的其他代码

 return view;
}

oCreateView in Ounit 我尝试添加进度条,例如

     ProgressDialog connectionProgressDialog = new ProgressDialog( getActivity());
      connectionProgressDialog.setCancelable(false);
      connectionProgressDialog.setCanceledOnTouchOutside(false);
      connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
      connectionProgressDialog.setMessage("Uploading Leads...");
      connectionProgressDialog.show();

但它从不显示

我在这个片段列表中使用view.getContext() 指向其构造函数上下文的路径

我尝试显示AlertDialog

                AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext());
                final EditText input = new EditText(v.getContext());
               alert.setView(input);
               alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int whichButton) {

                  //     Toast.makeText(getApplicationContext(), s_spin_text,
                        //       Toast.LENGTH_SHORT).show();


                   }
           });

            alert.setNegativeButton("Cancel",
          new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int whichButton) {
                           dialog.cancel();
                   }
                   });
           alert.show();

这个问题是不是因为这条线

     View view = inflater.inflate(
                R.layout.chemounit,
                container,
                false);

如果是?如何替换它

最好的问候

【问题讨论】:

    标签: android android-layout android-listview android-fragments android-progressbar


    【解决方案1】:

    我认为你应该使用:DialogFragment

    你有方法OnCreateDialog() 在那里你可以放你的代码:

    @Override
    public Dialog onCreateDialog(final Bundle savedInstanceState) {
      final ProgressDialog connectionProgressDialog = new ProgressDialog( getActivity());
      connectionProgressDialog.setCancelable(false);
      connectionProgressDialog.setCanceledOnTouchOutside(false);
      connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
      connectionProgressDialog.setMessage("Uploading Leads...");
      connectionProgressDialog
      return connectionProgressDialog;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多