我在onCreateView
方法中有这段代码,
代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_one, container, false);
}
这是按钮单击功能。我需要将其添加到
onCreateView Method.
btnCheckout = (Button) view.findViewById(R.id.btnCheckout);
btnCheckout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getContext(), SecondActivity.class);
startActivity(intent);
}
});
此行的错误为
Unreachable Statement
。
btnCheckout = (Button) view.findViewById(R.id.btnCheckout);
如何添加该代码。有谁能够帮我?提前谢谢。
答案 0 :(得分:0)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
btnCheckout = (Button) view.findViewById(R.id.btnCheckout);
btnCheckout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
return view;
}