2011年5月3日

Android 自訂對話框控件取得方法

若要使用自定義的對話框,要使用到裡面的控件時,要像下面這樣使用。


    LayoutInflater factory = LayoutInflater.from(DrawPanel.this);
    final View textEntryView = factory.inflate(R.layout.remote,
            null);
    AlertDialog dlg = new AlertDialog.Builder(DrawPanel.this)
            .setTitle("User Login")
            .setView(textEntryView)
            .setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int whichButton) {
                            final EditText user = (EditText) textEntryView.findViewById(R.id.userName);
                            final EditText serverName = (EditText)textEntryView.findViewById(R.id.serverName);
                            final EditText serverPort = (EditText)textEntryView.findViewById(R.id.serverPort);
                            String username = user.getText().toString();
                            String hostAddress = serverName.getText().toString();
                            String port = serverPort.getText().toString();


沒有留言:

ShareThis