我在片段中有这段代码,但它说无法解析方法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) {
}
});
}
答案 0 :(得分:4)
应该是:
FloatingActionButton fab = (FloatingActionButton)fragmentLayout.findViewById(R.id.fab);