正如標題所說,我有一個ExpandableListView
它正在從Fragment
ExpandableListView在TabHost沒有出現在片段
加載TabHost
裏面我可以得到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
...
我已經嘗試在創建視圖之前,在創建視圖之後,在創建活動之後,對'ExpandableListView'做的工作......似乎沒有任何工作。 此外,我試着調用'notifyDataSetChanged',沒有運氣:-( – Randy
我驗證了方法正在運行,並且正在設置變量。適配器正在獲取它所需的信息,並且正在設置爲'ExpandableListView '...一切都在發生,因爲它應該,但列表視圖永遠不會顯示在片段的初始加載中 – Randy
我向原始問題添加了更多信息 – Randy