Start a new Activity from Fragment

前端 未结 7 2061
遇见更好的自我
遇见更好的自我 2020-12-05 08:09

Using Android Studio, I have my MainActiviy class with a Placeholder fragment. This fragment has buttons, but one has to load an Activity. How does one do this? I was tol

7条回答
  •  孤城傲影
    2020-12-05 08:38

    In case of fragment, write getActivity() to get activity context instead of giving the name of activity explicitly. For example, if you want to open SecondActivity from a fragment,

    Intent intent=new Intent(getActivity(),SecondActivity.xml); StartActivity(i);

提交回复
热议问题