欢迎登录

Fragment内的按钮添加监听并跳转到另一个Activity

:2018-05-31    :210 次   :1741 字   

public class Robot extends Fragment{
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.robot_layout, container, false);
        return view;
    }
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Button button1 = (Button) getActivity().findViewById(R.id.robot_start);
        Button button2 = (Button) getActivity().findViewById(R.id.robot_create);
        button1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), RobotActivity.class);
                startActivity(intent);
            }
        });
    }}
    暂无评论,快来抢沙发吧!
×