android-dialog
Create a custom dialog with radio buttons list
best and easy way…… void dialog(){ AlertDialog.Builder alt_bld = new AlertDialog.Builder(this); //alt_bld.setIcon(R.drawable.icon); alt_bld.setTitle(“Select a Group Name”); alt_bld.setSingleChoiceItems(grpname, -1, new DialogInterface .OnClickListener() { public void onClick(DialogInterface dialog, int item) { Toast.makeText(getApplicationContext(), “Group Name = “+grpname[item], Toast.LENGTH_SHORT).show(); dialog.dismiss();// dismiss the alertbox after chose option } }); AlertDialog alert = alt_bld.create(); alert.show(); ///// grpname is a array where … Read more
How to display progress dialog before starting an activity in Android?
You should load data in an AsyncTask and update your interface when the data finishes loading. You could even start a new activity in your AsyncTask’s onPostExecute() method. More specifically, you will need a new class that extends AsyncTask: public class MyTask extends AsyncTask<Void, Void, Void> { public MyTask(ProgressDialog progress) { this.progress = progress; } … Read more
How to disable BottomSheetDialogFragment dragging
There is simpler way of achieving the same after material design 1.2.0 was released. https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetBehavior#setdraggable When calling from BottomSheetDialogFragment: override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog bottomSheetDialog.setOnShowListener { val bottomSheet = bottomSheetDialog .findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet) if (bottomSheet != null) { val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(bottomSheet) behavior.isDraggable = false } } return bottomSheetDialog … Read more
Adding positive / negative Button to DialogFragment’s Dialog
This is how I figured it out. I erased the onCreateView and altered the onCreateDialog. This link actually had the answer so all the credit should go there. I’ve just posted it just in case anyone bumps in this question first. @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder b= new AlertDialog.Builder(getActivity()) .setTitle(“Enter Players”) .setPositiveButton(“OK”, new … Read more
Remove black background on custom dialog
public MyAlertDialog( Context context, int theme ) extends AlertDialog { super(context, theme); getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); }
How do I fire an event when click occurs outside a dialog
When dialog.setCanceledOnTouchOutside(true); then you just override onCancel() like this: dialog.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { //When you touch outside of dialog bounds, //the dialog gets canceled and this method executes. } } ); Type your code inside the onCancel() method so it runs when the dialog gets canceled.
Get date from datepicker using dialogfragment
Constructor fo DatePickerDialog takes DatePickerDialog.OnDateSetListener as second parameter, so maybe you should implement that interface in your parent activity EditSessionActivity (not in DatePickerFragment ) and change this line: return new DatePickerDialog(getActivity(), this, year, month, day); into this: return new DatePickerDialog(getActivity(), (EditSessionActivity)getActivity(), year, month, day); And then your activity should looks like this: public class EditSessionActivity … Read more
Proper way of dismissing DialogFragment while application is in background
DialogFragment has a method called dismissAllowingStateLoss()
How to create a number picker dialog?
I have made a small demo of NumberPicker. This may not be perfect but you can use and modify the same. public class MainActivity extends Activity implements NumberPicker.OnValueChangeListener { private static TextView tv; static Dialog d ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.textView1); Button b = (Button) findViewById(R.id.button11); b.setOnClickListener(new … Read more