Android listview项目中的Google地图
我想把地图放在listview项目中。我想像这样实现! ![在此处输入图像描述][1] 我扩展了碎片活动 主要活动Android listview项目中的Google地图,android,google-maps,Android,Google Maps,我想把地图放在listview项目中。我想像这样实现! ![在此处输入图像描述][1] 我扩展了碎片活动 主要活动 @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maplist); mlayoutInflater = this.getLayoutInflater(
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maplist);
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);
if (aMap == null) {
aMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.textView.setText(data[position]);
return convertView;
}
};
listView.setAdapter(baseAdapter);
xml,下面是我添加到listview的每个项目
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
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.google.android.gms.maps.SupportMapFragment" />
谷歌可能会在v21中解决这个问题。您可以尝试将支持库更新到v21 对于较旧的支持库,可以尝试使用以下代码覆盖mapFragment的onDestoryView()方法:
public void onDestroyView() {
super.onDestroyView();
FragmentManager fm = getActivity().getSupportFragmentManager();
Fragment fragment = (fm.findFragmentById(R.id.map));
FragmentTransaction ft = fm.beginTransaction();
ft.remove(fragment);
ft.commit();
}
提前谢谢,我有这个问题几天了,所以我需要帮助
public void onDestroyView() {
super.onDestroyView();
FragmentManager fm = getActivity().getSupportFragmentManager();
Fragment fragment = (fm.findFragmentById(R.id.map));
FragmentTransaction ft = fm.beginTransaction();
ft.remove(fragment);
ft.commit();
}