我试图将浮动按钮添加到片段中,但是使用findViewById创建按钮时出现错误。public class HomeFragment extends Fragment {FloatingActionButton fab;@Nullable@Overridepublic View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_home, container,false); fab = (FloatingActionButton) getView().findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(getActivity(), ProfileActivity.class)); } });}}错误:fab =(FloatingActionButton)getView()。findViewById(R.id.fab);“无法到达的陈述”
添加回答
举报
0/150
提交
取消