N
N
newdancer2015-08-08 22:14:16
Android
newdancer, 2015-08-08 22:14:16

How to call 2 Fragment Dialog from one activity?

How to call 2 Fragment Dialog from one activity?
from the activity I declare and call:

// для DialogFragment
 DialogFragment dlgstart;
 DialogFragment dlgfinish;
// инициализируем fragment
dlgstart = new Startdlg();
dlgfinish = new Finishdlg();

//вызываю
dlgstart.show(getFragmentManager(), "dlgstart");
dlgfinish.show(getFragmentManager(), "dlgfinish");

class for fragment
public class Startdlg extends DialogFragment implements OnClickListener {
  
  final String LOG = "myLogs";
  Toast toast;
  int level;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      //getDialog().setTitle("Title!"); 
      // ставим прозрачный цвет
      getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
      
      // убираем title из окна
      getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
      
      View v = inflater.inflate(R.layout.startdlg, null);
      v.findViewById(R.id.butlevel1).setOnClickListener(this);
      v.findViewById(R.id.butlevel2).setOnClickListener(this);
      v.findViewById(R.id.butlevel3).setOnClickListener(this);
      return v;
    }
    
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        Log.d(LOG, "Dialog 1: onDismiss");
      }

      public void onCancel(DialogInterface dialog) {
        super.onCancel(dialog);
        Log.d(LOG, "Dialog 1: onCancel");
        Toast.makeText(getActivity(),getActivity().getString(R.string.alert_nolevelvub), Toast.LENGTH_SHORT).show();
        getActivity().finish();
      }

      public static interface OnCompleteListener {
            public abstract void onComplete(int time);
        }

        private OnCompleteListener mListener;

public void onAttach(Activity activity) {
    try {
        this.mListener = (OnCompleteListener)activity;
    }
    catch (final ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnCompleteListener");
    }
    super.onAttach(activity);
}

  @Override
  public void onClick(View v) 
  {
    Log.d(LOG, "Dialog 1: " + ((Button) v).getText());
      switch (v.getId()) {
    case R.id.butlevel1:
      level=1;
      break;
    case R.id.butlevel2:
      level=2;
      break;
    case R.id.butlevel3:
      level=3;
      break;
    }
      mListener.onComplete(level); 
     Toast.makeText(getActivity(),getActivity().getString(R.string.alert_levelvub)+" "+((Button) v).getText(), Toast.LENGTH_SHORT).show();
    dismiss();
  }

}

how to call the second similar dialogue?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question