只需在对应的Fragment.java文件中,做如下的操作:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//默认是:return inflater.inflate(R.layout.fragment_index, container, false);
//先定义一个 View ,而不返回。
final View view = inflater.inflate(R.layout.fragment_my, container, false);
//通过id,绑定退出登录按钮组件
Button mBtnLogout = view.findViewById(R.id.btn_logout);
//设置退出登录的点击事件
mBtnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(),LoginActivity.class);
startActivity(intent);
}
});
//返回 view
return view;
}
最后
以上就是还单身发箍最近收集整理的关于(YM学习笔记)Android--Fragment跳转到Activity的方法的全部内容,更多相关(YM学习笔记)Android--Fragment跳转到Activity内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复