我想使用片段中创建的按钮来调用类。这是包含按钮的片段的代码。
public class FragmentSecondPage extends Fragment{
View root;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle){
root = inflater.inflate(R.layout.fragment_page2, container, false);
return root;
}
}
我想从infragment_page2按钮启动一个类SplashActivity.class。有人可以帮帮我吗?
答案 0 :(得分:2)
//Create Intent that would call the Next Activity and since you are in Fragment you need to call getActivity() instead of this
Intent myIntent = new Intent(getActivity(), SplashActivity.class);
// This function will replace the currently running activity with new one
getActivity().startActivity(myIntent);