Skip to main content

Add Edittext Inside Dialog Box

Add Edittext Inside Dialog Box






If you haven`t yet watched the video...Watch it right now!!!



The code used in the above video is available here.

final EditText edittext1= new EditText(MainActivity.this);
LinearLayout.LayoutParams lpar = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
edittext1.setLayoutParams(lpar);
dialog.setView(edittext1);








textview1.setText(edittext1.getText());







Comments

  1. It shows error... For line :
    dialog.setView(edittext1);

    And the erorrs says that dialog cannot be resolved.

    ReplyDelete
    Replies
    1. This happens because you forgot to create a dialog component Whit the same name of the one called in code as above!

      Delete
    2. One more thing you should remember is that you should create a textview and me it as the one is going to receive the parameter

      Delete
    3. You should create a dialogue companent named 'dialog' to work this code.

      Delete
  2. Change dilog name with your dialog name
    Like
    dialog1.setView

    ReplyDelete
  3. How to do that when you enter one text was displayed another?

    ReplyDelete
  4. Please I want to add two edit text in the dialog in sketchware

    ReplyDelete
    Replies
    1. Use (new) LinearLayout instead, create 2 (new) EditText then use AddChild.

      Delete
  5. Use .toString() like edittext1.getText().toString();

    ReplyDelete

Post a Comment

Did you like this tutorial ?