【发布时间】:2014-08-26 09:10:04
【问题描述】:
我已经创建了导航抽屉,并且每个列表项 onclick 都会加载一个片段。有将加载地图的主页片段。我已经在扩展片段活动的活动中加载了地图,但没有在片段内部加载。我收到错误但没有得到它所以需要建议。
//HomeFragment.java
public class HomeFragment extends Fragment implements OnInfoWindowClickListener {
GoogleMap myMap;
private Marker marker;
private Marker marker2;
private Marker marker3;
// GPSTracker class
GpsTracker gps;
// textview
TextView DestinationDistance;
double latitude;
double longitude;
double lat2 = 23.7818442;
double lng2 = 90.3245161;
double lat3 = 23.7818442;
double lng3 = 90.4245161;
private Polyline line;
private ViewGroup userLayout;
// user info views
private TextView txtDistance;
private TextView txtETA;
private int count = 0;
private ArrayList<Polyline>pl;
public HomeFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_home, container, false);
userLayout = (ViewGroup) v.findViewById(R.id.userLayout);
txtDistance = (TextView) v.findViewById(R.id.txtV2);
txtETA = (TextView) v.findViewById(R.id.txtV3);
myMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
myMap.setOnInfoWindowClickListener(this);
/*Here will be other code to execute asynctask,
location detect, add marker etc */
return v;
}
@Override
public void onInfoWindowClick(Marker arg0) {
// TODO Auto-generated method stub
}
}
*此代码出现错误
'The method getSupportFragmentManager() is undefined for the type HomeFragment'
//fragment_home.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/userLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.0"
android:orientation="horizontal"
android:visibility="gone" >
<LinearLayout
android:id="@+id/user_infoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="#fff" >
<TextView
android:id="@+id/txtV1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="#000"
android:text="Profile Picture" />
</LinearLayout>
<LinearLayout
android:id="@+id/position_infoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="vertical" >
<TextView
android:id="@+id/txtV2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:text="" />
<TextView
android:id="@+id/txtV3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:text="" />
<Button
android:id="@+id/btnMsg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:text="Send Message" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
标签: android android-fragments google-maps-api-2