-1

アプリにダイアログ ボックスを追加して、ユーザーが希望する IP アドレスを入力できるようにしたいと考えています。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Please put Ip address")
            ------> here the user can type on the dialog in String
            .setNeutralButton("Add", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    printer = new PrinterObject("134.188.204.155");--->the result text from dialog


   ....
    }
            });
        AlertDialog alert = builder.create();
        alert.show();

誰もそれを追加する方法を知っていますか?

4

2 に答える 2

1

これを試して...

AlertDialog.Builder builder = new Builder(this);
        builder.setTitle("Please put Ip address");
        builder.setMessage("");
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.alert, null);
        final EditText ipfield = (EditText) view.findViewById(R.id.ipfield);

        builder.setView(view);
        builder.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int arg1) {
                        // do what you need
                    }
                });

        builder.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int arg1) {
                        dialog.dismiss();
                    }
                });
        AlertDialog dialog = builder.create();
        dialog.show();
于 2013-10-15T08:11:00.893 に答える