Skip to main content

Add Checkbox Inside Dialog Box | Sketchware tutorial

Add Checkbox Inside Dialog Box 






If you haven`t yet watched the video,Watch it Now...!


Open your Sketchware project.Add Dialog Box component.
Go to the logic section & add the blocks which are necessary to create a dialog box.
A screenshot is given below for your reference.

                                  



Now you have to make some modifications.In order to add checkbox you have to use add source directly block.Add the following code inside it.Screenshot is given below for your reference


final CheckBox cb1 = new CheckBox(MainActivity.this);
cb1.setText("CheckBox");
LinearLayout.LayoutParams lpar = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
cb1.setLayoutParams(lpar);
dialog.setView(cb1);





Inside the block "dialog OK Button Clicked", add the following code using add source directly block


if(cb1.isChecked()){


After adding add source directly block,Use a toast block to toast "Checked..!"


Again Use add source directly block and add the following code

}
else
{

After adding the code , use a toast block to toast "Did not Check...!"


After adding the toast block , use add source directly block and this code

}



                                           



Thats It :)



If you have any doubts comment below .









Comments

  1. how to add at least 4 checkbox in dialog?

    ReplyDelete
    Replies
    1. Hi. Have you figured it out yet? I still need to know how to add multiple checkbox in dialog.

      Delete
  2. I had to add an editText field. So it should still be the same. Just add all of your checkboxes. You'll have to add them individually. Checkbox cb1 = new Checkbox(MainActivity.this); Checkbox cb2... etc. Then, set them individually. dialog.setView(cb1); dialog.setView(cb2); etc.

    ReplyDelete

Post a Comment

Did you like this tutorial ?

Popular posts from this blog

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());

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