2 u010909739 u010909739 于 2014.12.16 09:40 提问

高德地图中如何把map放到每个Listview的item中
map

我的MainActivity的代码
public class MainActivity extends FragmentActivity {
private ListView listView;
private BaseAdapter baseAdapter;
private LayoutInflater mlayoutInflater;
private AMap aMap;
private MapView mapView;
String data[] = {"地图1","地图2"};

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maplist);

// init();
mlayoutInflater = this.getLayoutInflater();
listView = (ListView) findViewById(R.id.maplist);

    baseAdapter = new BaseAdapter(){

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return data.length;
        }

        @Override
        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder = null;
            if(convertView == null){
                viewHolder = new ViewHolder();
                convertView = mlayoutInflater.inflate(R.layout.mapcontent, null);
                viewHolder.textView = (TextView) convertView.findViewById(R.id.text);


                convertView.setTag(viewHolder);

            }else{
                //viewHolder = (ViewHolder) convertView.getTag();
            }
                viewHolder.textView.setText(data[position]);
                if (aMap == null) {
                    aMap = ((SupportMapFragment) getSupportFragmentManager()
                            .findFragmentById(R.id.map)).getMap();
                }

// FragmentManager fm = getSupportFragmentManager();
// FragmentTransaction fra = fm.beginTransaction();
// Fragment fragment = (fm.findFragmentById(R.id.map));
// fra.add(R.id.map, fragment);
// ViewHolder viewHolder = null;
// viewHolder = new ViewHolder();
// convertView = mlayoutInflater.inflate(R.layout.mapcontent, null);
// viewHolder.textView = (TextView) findViewById(R.id.text);
// viewHolder.textView.setText(data[position]);
//

//

return convertView;

        }


    };

    listView.setAdapter(baseAdapter);
}

我的xml
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text"

    />
</LinearLayout>
<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.amap.api.maps2d.SupportMapFragment" 
    android:name="com.testing.svma.MainActivity"/>


1个回答

devmiao
devmiao   Ds   Rxr 2014.12.16 09:55
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!