passing context as argument of DialogFragment

后端 未结 4 2102
挽巷
挽巷 2021-02-01 03:15

it\'s possible to pass a context variable to a DialogFragment?

i\'ve use this code inside dialog for passing a string:

public static ConfirmDialog newIns         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 04:17

    use like this:

    public class Dialog extends DialogFragment implements OnClickListener {
        public void onClick(View v) {
        switch (v.getId()) {
            case R.id.message: {
                this.startActivity(new Intent(context, Login.class));
                                     //or use getActivity() instead of context
                }
                break;
             }
        }
        @Override
        public void onAttach(Activity activity) {
            // TODO Auto-generated method stub
            super.onAttach(activity);
            context=activity;
        }
    }
    

提交回复
热议问题