Skip to main content

Posts

Showing posts from December, 2014

Passing the click events back to the dilaog's host in android

In this post i am going to show you how to get the dialog's click events back to the host activity or fragment. By default the click events of a dialog is handled by the DialogFragment. You can transfer the click events back to the host activity or fragment by declaring an interface in the dilalog class. Ads by Google In this example we have a TextView in the activity_main.xml file. We have to change the font color of the TextView using an alert dialog with single choice list. So the user can select a color from the dilalog and we set that particular color as the font color for the TextView. ColorDialog.java 1: public class ColorDialog extends DialogFragment 2: { 3: CharSequence[] sequence = {"RED","GREEN","BLUE"}; 4: String color_selection; 5: @Override 6: public Dialog onCreateDialog(Bundle savedInstanceState) { 7: AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 8: