正如标题中所述,ExpandableListView
内有TabHost
,Fragment
正在加载ExpandableListView
我可以在没有TabHost
的情况下正常显示TabHost
,但是一旦我添加了ExpandableListView
它就没有显示。
我也得到了这一点,当我更改标签时,列表会显示,但在初次加载视图时,public class Categories extends Fragment {
SearchView searchView; //Not doing anything yet
LayoutInflater inflater;
ExpandableListView expandableListView;
TabHost tabHost;
private ArrayList<String> parentItems = new ArrayList<String>();
private ArrayList<Object> childTitles = new ArrayList<Object>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.categories_tabs, null);
searchView = (SearchView) layout.findViewById(R.id.searchView);
this.inflater = inflater;
tabHost = (TabHost) layout.findViewById(R.id.tabhost); // The activity TabHost
tabHost.setup();
TabHost.TabSpec spec; // Reusable TabSpec for each intent;
try
{
//setup tab name, display text, and layout
spec = tabHost.newTabSpec(getResources().getString(R.string.events))
.setIndicator(" " + getResources().getString(R.string.events) + " ")
.setContent(R.id.categoriesLayout); //must be id, not layout or xml
//add tab
tabHost.addTab(spec);
spec = tabHost.newTabSpec(getResources().getString(R.string.venues))
.setIndicator(" " + getResources().getString(R.string.venues) + " ")
.setContent(R.id.categoriesLayout); //must be id, not layout or xml
tabHost.addTab(spec);
//finish adding tabs
tabHost.getTabWidget();
}
catch(Exception e)
{
Log.v(getActivity().getResources().getString(R.string.app_name), "Failed to load tab host");
}
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener()
{
@Override
public void onTabChanged(String s)
{
displayTab();
}
});
return layout;
}
private void displayTab()
{
//set parentItems - not shown
setGroupParents();
//set childTitles - not shown
setChildData();
MyExpandableAdapter adapter = new MyExpandableAdapter(parentItems, childTitles, childDescriptions);
adapter.setInflater(inflater, getActivity());
expandableListView.setAdapter(adapter);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
expandableListView = (ExpandableListView) view.findViewById(R.id.list);
displayTab();
}
不存在。
以下是代码:
displayTab
运行ExpandableListView
功能会在切换标签时显示tabHost.setCurrentTab(1);
tabHost.setCurrentTab(0);
,但我需要它在加载屏幕后立即显示列表。我做错了什么?
附录
好的,所以现在我真的很困惑......如果我把
onStart()
在我的ExpandableListView
,displayTab();
显示,但如果我只是放
OnTabChangeListener
在那里,它没有显示。 displayTab
所做的一切都在运行{{1}} ...
答案 0 :(得分:0)
您在创建视图后使用ExpendableListView,这不是必需的,您可以在onCreateView中完成工作。也许在displayTab()中调用适配器上的notifyDataSetChanged就足够了。
或者您可以将代码移动到正确的回调中。
如果没有帮助,请显示适配器代码
因此,如果tab已更改,则会显式调用displayTab。你确保首次初始化时调用Method吗?我的意思是证实我跑了?像sysout(运行)?