【问题标题】:findViewById not resolved [duplicate]findViewById 未解决 [重复]
【发布时间】: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();

标签: android view find


【解决方案1】:

应该是:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 2017-03-22
    • 2019-05-03
    相关资源
    最近更新 更多