0

我有在其中扩展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;
}

oCreateViewOunit我尝试添加进度条

     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);

如是 ?如何更换它

最好的祝福

4

1 回答 1

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;
}
于 2012-06-14T14:02:31.057 回答