btn_setIp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                LayoutInflater inflater = getLayoutInflater();
                final View layout = inflater.inflate(R.layout.dialog_layout,
                        (ViewGroup) findViewById(R.id.dialog));
                new AlertDialog.Builder(MyActivity.this).setTitle("设置Ip与端口")
                        .setView(layout)
                        .setPositiveButton("确定",new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                edit_ip = (EditText) layout.findViewById(R.id.edit_ip);
                                edit_port = (EditText) layout.findViewById(R.id.edit_port);
                                ip = edit_ip.getText().toString();
                                port = Integer.parseInt(edit_port.getText().toString());
                                Log.v("ip",ip);
                                Log.v("port",port+"");
                                new Thread(){
                                    @Override
                                    public void run() {
                                        try {
                                            socket = new Socket(ip,port);
                                            fromClient = new ObjectOutputStream(socket.getOutputStream());
                                            fromsServer = new ObjectInputStream(socket.getInputStream());

                                        } catch (IOException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }.start();
                            }
                        })
                        .setNegativeButton("取消", null).show();
            }
        });

PS:做下记录


Chao
127 声望1 粉丝