0

这是谷歌说用来创建自定义警报对话框的代码(它说要创建自己的布局,然后将该布局用于 setContentView)

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();

// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.dialog_signin, null))
// Add action buttons
       .setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int id) {
               // sign in the user ...
           }
       })
       .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               LoginDialogFragment.this.getDialog().cancel();
           }
       });      
return builder.create();
}

谷歌然后说在另一个类中创建这个类的一个实例,然后用 show() 方法显示它,但是 show 方法需要一个片段管理器,当你尝试创建它时,片段管理器会出错。

这是说明 http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

我需要在启动新活动的警报对话框中添加一个微调器

如果有人能弄清楚如何让这个工作(让对话弹出)并发布它会很棒

4

1 回答 1

1

你可以Alert Dialog with spinner这样创建

更新

 public class WvActivity extends Activity {

 TextView tx;
 String[] s = { "India ", "Arica", "India ", "Arica", "India ", "Arica",
    "India ", "Arica", "India ", "Arica" };
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

 final ArrayAdapter<String> adp = new ArrayAdapter<String>(WvActivity.this,
        android.R.layout.simple_spinner_item, s);

 tx= (TextView)findViewById(R.id.txt1);
 final Spinner sp = new Spinner(WvActivity.this);
 sp.setLayoutParams(new     LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
 sp.setAdapter(adp);

 AlertDialog.Builder builder = new AlertDialog.Builder(WvActivity.this);
 builder.setView(sp);
 builder.create().show();
 }
}
于 2013-04-27T04:46:48.503 回答