Android full-screen dialog callback issue

前端 未结 4 2113
暖寄归人
暖寄归人 2020-12-28 21:46

I am having trouble wrapping my head around something but let me first describe my setup:

\"flow\"

I ha

4条回答
  •  情话喂你
    2020-12-28 22:32

    I don't see code from your post. So I am guessing your code structure as a start. First build your dialog with a listener and process setPositiveButton() and the onClick event.

    Code suggestion:

    public class ChildrenSpecificationFragment extends Fragment {
    ...
    
    public void passData(Object obj) {
    }
    
       class SubChildFragment extends Fragment {
           AlertDialog.Builder builder = new AlertDialog.Builder(thisContext);
           ...
           // Add the buttons...
           builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
               ...
               passData(Object obj);   // pass data to the outer fragment class
    

    Notes:

    • SubChildFragment, for example, is an inner class derived from Fragment. It can call the public method passData() in the outer class ChildrenSpecificationFragment for passing any data you need.
    • I am using an inner class because I think this is what you meant in your diagram by

    Add child full-screen fragment

    • This coding technique is easier than starting a new Activity and Intent.

    For showing fullscreen dialogs, there is a good Google webpage I think @ Dialog - Fullscreen. Search text for "Showing a Dialog Fullscreen or as an Embedded Fragment".

提交回复
热议问题