【发布时间】:2016-12-06 15:35:18
【问题描述】:
我在片段中有这段代码,但它说 cannot resolve method 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) {
}
});
}
【问题讨论】:
-
需要给根视图:fragmentLayout.findViewById(..);
-
使用 fragmentLayout.findViewById();