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

How to set DialogFragment’s width and height?

If you convert directly from resources values: int width = getResources().getDimensionPixelSize(R.dimen.popup_width); int height = getResources().getDimensionPixelSize(R.dimen.popup_height); getDialog().getWindow().setLayout(width, height); Then specify match_parent in your layout for the dialog: android:layout_width=”match_parent” android:layout_height=”match_parent” You only have to worry about one place (place it in your DialogFragment#onResume). Its not perfect, but at least it works for having a RelativeLayout as the … 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 show a dialog to confirm that the user wishes to exit an Android Activity?

In Android 2.0+ this would look like: @Override public void onBackPressed() { new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(“Closing Activity”) .setMessage(“Are you sure you want to close this activity?”) .setPositiveButton(“Yes”, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }) .setNegativeButton(“No”, null) .show(); } In earlier versions it would look like: @Override public boolean … Read more

How to dismiss the dialog with click on outside of the dialog?

You can use dialog.setCanceledOnTouchOutside(true); which will close the dialog if you touch outside of the dialog. Something like, Dialog dialog = new Dialog(context) dialog.setCanceledOnTouchOutside(true); Or if your Dialog in non-model then, 1 – Set the flag-FLAG_NOT_TOUCH_MODAL for your dialog’s window attribute Window window = this.getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); 2 – Add another flag to windows properties,, … Read more

How to handle screen orientation change when progress dialog and background thread active?

Edit: Google engineers do not recommend this approach, as described by Dianne Hackborn (a.k.a. hackbod) in this StackOverflow post. Check out this blog post for more information. You have to add this to the activity declaration in the manifest: android:configChanges=”orientation|screenSize” so it looks like <activity android:label=”@string/app_name” android:configChanges=”orientation|screenSize|keyboardHidden” android:name=”.your.package”> The matter is that the system destroys … Read more