Android - Custom Dialog - Can't get text from EditText

前端 未结 6 775
清歌不尽
清歌不尽 2020-12-01 12:00

I have a problem with a custom dialog.
My dialog consists of a TextView, EditText and an \"Ok\" Button. After clicking \"Ok\", it should get t

6条回答
  •  春和景丽
    2020-12-01 12:50

    Hope it will help you.

    private void inputFromDialog() {
    
        final Dialog dialog = new Dialog(SplashActivity.this);
        dialog.setContentView(R.layout.view_dialog);
        dialog.setTitle("Title");
        dialog.setCancelable(false);
        dialog.show();
    
        Button button = (Button) dialog.findViewById(R.id.continue_BTN);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
    
                EditText inputET=(EditText)dialog.findViewById(R.id.input_ET);
    
    
                if (inputET.getText().toString().equals("")){
    
                    inputET.setError("This field is required");
    
                }else {
    
                    mssid = inputET.getText().toString();
                    dialog.cancel();
                    Toast.makeText(SplashActivity.this, mssid, Toast.LENGTH_SHORT).show();
                }
    
            }
        });
    
    
    
    }
    

提交回复
热议问题