代码如下,lv的值为什么会一直为null?
MyFragment类:
public class MyFragment extends Fragment {
TextView tv;
ListView lv;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.list_item, container, false);
lv = (ListView) v.findViewById(R.id.wifiTv);
tv = (TextView) v.findViewById(R.id.textView);
Judgement();
return v;
}
}
Layout文件:

Debug如图
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
layout文件使用错了,在你贴出的layout代码里并没有看到RelativeLayout的定义,但是tv却出现了RelativeLayout
还有,建议控件的初始化写在onViewCreated而非onCreateView