这是我拥有的课程,并给了我错误:
public class ShowCarMapChild extends MapActivity {
private MapView mapView;
private Car car;
private String tag;
@Override
protected void onCreate(Bundle icicle) {
// TODO Auto-generated method stub
super.onCreate(icicle);
Log.d("hemendik pasetan da?", "bai!!");
setContentView(R.layout.car_map_view);
}
public void setCar(Car car){
this.car = car;
}
public void setTag (String tag){
this.tag = tag;
}
public String getTag (){
return tag;
}
public View getMapView(Context context){
Log.d("getMapView", "pass");
setContentView(R.layout.car_map_view);
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view = infalInflater.inflate(R.layout.car_map_view, null);
setMap(view,context);
return view;
}
public void setMap(View view, Context context){
mapView = (MapView) view.findViewById(R.id.mapShowCarLocation);
MapController mc = mapView.getController();
mc.animateTo(car.getLocation());
mc.setZoom(15);
PinpointItem point = new PinpointItem(car.getLocation(), car, context);
Drawable d = getResources().getDrawable(R.drawable.pinpoint);
CustomPinpointOverlay overlay = new CustomPinpointOverlay(d);
overlay.insertPinpoint(point);
mapView.getOverlays().add(overlay);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
布局:car_map_view.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="150dip"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapShowCarLocation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0UFOPeLgKxoW8VGjdzV5QN6N53N7733i1kTFI3g"
android:enabled="true" />
</LinearLayout>
正如我在标题中所说的错误是在我执行 setContentView 时。我还必须说,我正在尝试使用此类作为子类放入可扩展列表中。如果需要其余代码,也请告诉我。
这是我调用getMapView()方法的地方。来自 BaseExpandableListAdapter
public class ShowCarExpandListAdapter extends BaseExpandableListAdapter {
....
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view,
ViewGroup parent) {
// TODO Auto-generated method stub
if (view == null){
if (groupPosition == 0){
Log.d("getChildView", "pass");
ShowCarMapChild mapChild = (ShowCarMapChild) getChild(groupPosition, childPosition);
view = mapChild.getMapView(context);
//LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
//ShowCarMapChild mapChild = (ShowCarMapChild) getChild(groupPosition, childPosition);
//view = infalInflater.inflate(R.layout.car_map_view, null);
//MapView mv = mapChild.getMap(view, context);
//mv.setTag(mapChild.getTag());
}else{
Log.d("getChildView", "pass from else");
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
ShowCarExpandChild child = (ShowCarExpandChild) getChild(groupPosition, childPosition);
view = infalInflater.inflate(R.layout.car_child, null);
TextView tv = (TextView) view.findViewById(R.id.tvChild);
tv.setText(child.getName());
tv.setTag(child.getTag());
}
}
return view;
}
.....