该问题已经调试了3天,今天终于搞定,特此记录:
问题说明:expandablelistview放在viewpager中无法显示,第一天抛出空指针异常,后来调试无误,却一直不显示,现记录如下:
1, 空指针问题:
Viewview=LayoutInflater.from(this).inflate(R.layout.tab02, null);//这一行固定了要在什么XML中寻找,而如果无from(this) 默认是在activity_main.xml中找所需的东西peoplelist= (ExpandableListView)view.findViewById(R.id.people_lv);
2、针对上面的问题,应该用如下方法,就是如何在ViewPage中使用ExpandableListView总是无法显示,其根本原因是:
即便1中出现的view也是无法在总界面中显示的,必须再ViewPage中进行定义,而实际在初始化viewpage的时候中已经有了这些代码,应加以运用。
LayoutInflater mInflater = LayoutInflater.from(this);
Viewtab01= mInflater.inflate(R.layout.tab01, null);
Viewtab02= mInflater.inflate(R.layout.tab02, null);
那么直接拿来用就可以了peoplelist = (ExpandableListView)tab02.findViewById(R.id.people_lv);就可以显示了。
其中
tab01,tab02是viewpage中子页面的xml id
people_lv是ExpandableListView的xml id.