Fragment跳转到Activity
在onCreateView中设置Button点击事件
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//设置跳转到MainActivity并销毁WelcomeActivity
View rootView = inflater.inflate(R.layout.fragment_three, null);//这里选择的是当前Fragment的xml布局
fr_bt_login = (Button) rootView.findViewById(R.id.fr_bt_login);//找到当前Fragment的Button按钮
fr_bt_login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(getActivity(),MainActivity.class); //在这里可以使用getActivity得到当前Activity
startActivity(intent);
getActivity().finish(); //销毁当前Activity
}
});
return rootView;
}