从片段

时间:2017-07-28 03:49:48

标签: android android-fragments android-activity android-imagebutton

我的Fragment课程中包含Button,我希望使用此activity开始新的button
有人可以帮帮我吗?

这是我的 MainFragment.class

public class MainFragment extends Fragment {

    public MainFragment() {

        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_main, container, false);
    }

}

1 个答案:

答案 0 :(得分:0)

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
  view.findViewById(R.id.buttonId).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(...));
        }
    });
}

buttonId替换为按钮的ID,并填写intent