-
-
Save RogerioDoCarmo/5f4b8d6e201f56368fcc6634535cb167 to your computer and use it in GitHub Desktop.
Custom Tabbed DialogFragment with alertdialog title, positive and negative buttons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TabbedDialog2 extends DialogFragment { | |
TabLayout tabLayout; | |
ViewPager viewPager; | |
View v = null; | |
@NonNull | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()) | |
.setNegativeButton("Close", | |
new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int whichButton) { | |
dialog.dismiss(); | |
} | |
} | |
); | |
dialogBuilder.setPositiveButton("Save", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
} | |
}); | |
dialogBuilder.setTitle("Add Beacon"); | |
//dialogBuilder.setCancelable(true); | |
// call default fragment methods and set view for dialog | |
if(v==null) | |
v = onCreateView(getActivity().getLayoutInflater(), null, null); | |
onViewCreated(v, null); | |
dialogBuilder.setView(v); | |
AlertDialog dg = dialogBuilder.create(); | |
//dg.setCanceledOnTouchOutside(false); | |
return dg; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
if(v==null) { | |
v = inflater.inflate(R.layout.dialog_sample,container,false); | |
tabLayout = (TabLayout) v.findViewById(R.id.tabLayout); | |
viewPager = (ViewPager) v.findViewById(R.id.masterViewPager); | |
CustomAdapter adapter = new CustomAdapter(getChildFragmentManager()); | |
adapter.addFragment("Boy",CustomFragment.createInstance("John")); | |
adapter.addFragment("Girl",CustomFragment.createInstance("Stacy")); | |
adapter.addFragment("Robot",CustomFragment.createInstance("Aeon")); | |
viewPager.setAdapter(adapter); | |
tabLayout.setupWithViewPager(viewPager); | |
} | |
return v; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment