参考:https://zhidao.baidu.com/question/241449421762648044.html
就是把activity中监听的Intent(MainActivity_login.this,......)换成 getActivity() 就可以了!
public class mineFragment extends Fragment {
public Button mine_btnexit;
public mineFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view =inflater.inflate(R.layout.fragment_mine,container,false);
mine_btnexit=view.findViewById(R.id.mine_btnexit);
mine_btnexit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent= new Intent(getActivity(),MainActivity_login.class);
//MainActivity_login.class是要跳转到的
startActivity(intent);
}
});
return view;
}
}
|