我收到错误
PM_section 类型的 findViewById(int) 方法未定义
当尝试实现我的 Expandable ListView 时。我确信这是一个常见错误,但我无法找到解决方案。我正在尝试学习片段之类的东西,从我开始以来,这一直是一场艰苦的战斗。我做了相当多的搜索,发现了很多结果,但这些结果似乎对我的情况没有帮助。
如果有人能给我任何见解,或者为我指明正确的方向,我将不胜感激。
我的小测试课如下
public class PM_section extends Fragment {
// CustomExpListView custExpListView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
View V = inflater.inflate(R.layout.fragment_pm_section_test, container, false);
CustomExpListView custExpListView = (CustomExpListView)
this.findViewById(R.id.ExpandableListView01);
return V;
}// end on create
}
CustomExpListView 类几乎是从 Android 示例项目中复制粘贴的,并且很高兴并且没有任何问题。
谢谢你帮助我。
If R.id.ExpandableListView01
是其一部分R.layout.fragment_pm_section_test
,然后替换this
with V
.
CustomExpListView custExpListView = (CustomExpListView)
V.findViewById(R.id.ExpandableListView01);
Fragment
s 没有findViewById()
方法。你需要使用你的充气View
相反,从您的布局中获取所有内容。
还可以考虑使用 Java 命名约定。变量以小写字母开头,而类以大写字母开头。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)