I have an ExpandableListView
in my Fragment
that shows some data. I call the Fragment
when i press an icon.
public void searchClick(){
Fragment frag = new Results();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.FragFaecher,frag).commit();
displayList();
}
displayList()
then should populate the List and show it
public void displayList(){
populateList();
expList = (ExpandableListView) findViewById(R.id.expList);
listAdapter = new ExpListAdapter(MainActivity.this,parentList);
expList.setAdapter(listAdapter);
}
In FragmentClass the Layout with the ExpandableListView
is inflated within the fragment_results
Layout
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_results, container, false);
return rootView;
}
fragment layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/results"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="?android:colorBackground"
android:clickable="true">
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?android:colorBackground"
android:childDivider="#000000"
android:id="@+id/expList" />
</RelativeLayout>
I suppose the problem is, that the displayList()
method tries to find a View
that is not yet created. I tried to return a boolean when the View
was created, but that did not work. Is there any other possible way to prevent this from happening?