I already extended SherlockMapActivity,which is a compatibilty library that allows tabbed like interface found in later versions of android.. The Problem is I have two Tabs. A Mapview Tab and a ListView Tab.The MapView works fine but the List View doesnt.I want a way to implement an expandablelistview without extending the expandablelistactivity..The Expandablelistview should appear under the listview tab.
The problem now is that the setListAdapter method is undefined in my Code..pls help.
public class MainActivity extends SherlockMapActivity implements LocationListener,ActionBar.TabListener {
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
private GeoPoint currentPoint;
private Location currentLocation = null;
private PlaceOverlay currPos;
private ViewSwitcher tswitcher;
public boolean showMiniHelp = true;
TableLayout tlayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
tswitcher = (ViewSwitcher)findViewById(R.id.viewSwitcher1);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = getSupportActionBar().newTab();
tab1.setText("Map View");
tab1.setTabListener(this);
getSupportActionBar().addTab(tab1);
ActionBar.Tab tab2 = getSupportActionBar().newTab();
tab2.setText("List View");
tab2.setTabListener(this);
getSupportActionBar().addTab(tab2);
mapView = (MapView)findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
mapController = mapView.getController();
mapController.setZoom(17);
getLastLocation();
drawCurrPositionOverlay();
drawStores();
drawSportLocations();
animateToCurrentLocation();
//ListViewSetup
// Construct Expandable List
final String NAME = "name";
final String IMAGE = "image";
final String DATA = "data";
final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>();
final HashMap<String, String> group1 = new HashMap<String, String>();
group1.put(NAME, "Group 1");
headerData.add( group1 );
final HashMap<String, String> group2 = new HashMap<String, String>();
group2.put(NAME, "Group 2");
headerData.add( group2);
final HashMap<String, String> group3 = new HashMap<String, String>();
group3.put(NAME, "Group 3");
headerData.add( group3);
final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();
final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>();
childData.add(group1data);
final ArrayList<HashMap<String, Object>> group2data = new ArrayList<HashMap<String, Object>>();
childData.add(group2data);
final ArrayList<HashMap<String, Object>> group3data = new ArrayList<HashMap<String, Object>>();
childData.add(group3data);
// Set up some sample data in both groups
for( int i=0; i<10; ++i) {
final HashMap<String, Object> map = new HashMap<String,Object>();
map.put(NAME, "Child " + i );
map.put(DATA, "Data " + i);
map.put(IMAGE, getResources().getDrawable((i%3==0? R.drawable.basketball : R.drawable.supermarket)));
( i%2==0 ? group1data : group2data ).add(map);
}
final HashMap<String, Object> map = new HashMap<String,Object>();
map.put(NAME, "Child x");
map.put(DATA, "Data x");
map.put(IMAGE, getResources().getDrawable(R.drawable.tennis));
group3data.add(map);
setListAdapter( new SimpleExpandableListAdapter(
this,
headerData,
R.layout.group_row,
new String[] { NAME, DATA }, // the names of the data
new int[] { R.id.groupname }, // the text field to populate with the field data
childData,
0,
null,
new int[] {}
) {
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
// Populate your custom view here
((TextView)v.findViewById(R.id.name)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME) );
((TextView)v.findViewById(R.id.data)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(DATA) );
((ImageView)v.findViewById(R.id.image)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(IMAGE) );
return v;
}
@Override
public View newChildView(boolean isLastChild, ViewGroup parent) {
return layoutInflater.inflate(R.layout.expandable_list_item_with_image, null, false);
}
}
);
ExpandableListView list = (ExpandableListView) findViewById(android.R.id.list);
list.setOnChildClickListener(new OnChildClickListener(){
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
System.out.println("Group:"+groupPosition+", Child: "+childPosition);
return true;
}
});
Absolutely it is! Even I had a similar problem.
Extending ExpandableListActivity just helps you by directly giving you the adapters and stuff.
But you can also define an ExpandableListView in your layout and declare all it’s adapters manually.
This tutorial will help you.
Good luck!