I have a working expandablelistview code, which works fine as a standalone. I have another working code for sliding tab views which I wrote separately.
Both these were written after going thru a number of blogs, android dev and stackoverflow questions.
When I try to combine and put the expandable listview in one of the fragments, I end up with an error, I am unable to resolve.
Here's the code from the Fragment piece:
public class Fragment1 extends Fragment {
private static final String NAME = "NAME";
private static final String IS_EVEN = "IS_EVEN";
private ExpandableListAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < 10; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "Group " + i);
curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < 2; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Child " + j);
curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
}
childData.add(children);
}
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
getActivity(),
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 },
childData,
android.R.layout.simple_expandable_list_item_2,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 }
);
setListAdapter(mAdapter);
}
}`
I keep getting error on the last line: 'The method setListAdapter(ExpandableListAdapter) is undefined for the type Fragment1'.
The rest of the code shows no error.
Please help. How can I correct this problem.
Fragment do not contains method
setListAdapter
. ListFragment do. You have to extend your fragment from this class to solve this problem.I was able to solve the problem myself.. For future reference, here's the code. Might be messy and needs cleanup, but it works for now!
@Divers & @Dixit - Thanx.
This post is almost 2 years old, but no answer in this page is a relevant one.
to answer PO question,
It's because
setListAdapter
is a method of ListFragment or ListActivity which is waiting for aListAdapter
or its subclasses as argument. You get this error because you gave it aExpandableListAdapter
which does not implement theListAdapter
interface.Hope this will help someone.