findViewById未解决

时间:2016-08-01 13:58:21

标签: android view find

我在片段中有这段代码,但它说无法解析方法findViewById

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    View fragmentLayout = inflater.inflate(R.layout.fragment_note_detail, container, false);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
}

1 个答案:

答案 0 :(得分:4)

应该是:

FloatingActionButton fab = (FloatingActionButton)fragmentLayout.findViewById(R.id.fab);