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. This says: "cannot convert from editable to string"

    ReplyDelete
    Replies
    1. Use .toString() like edittext1.getText().toString();

      Delete
  5. 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

Post a Comment

Did you like this tutorial ?

Popular posts from this blog

Create Custom Popup Window using Sketchware

Create Custom Popup Window using Sketchware Refer the video below if  you get stuck.  1) Add a custom view named window.You can name it according to your wish.  2)Design your popup window.  2) Now, In the logic section,In OnCLick event of button.Add the following  code Create a view View popupView = getLayoutInflater().inflate(R.layout.window, null); Popup window  final PopupWindow popup = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); Initialize  Button b1 = popupView.findViewById(R.id.button1); Button b2 = popupView.findViewById(R.id.button2); OnClickListeners b1.setOnClickListener(new OnClickListener() { public void onClick(View view) { //below code will dismiss the popup window popup.dismiss(); } }); b2.setOnClickListener(new OnClickListener() { public void onClick(View view) { popup.dismiss(); } }); Show the popup window  popup.showAtLoc