我收到了错误:
引起:android.view.InflateException:二进制XML文件行#1: 膨胀类片段时出错引起的: java.lang.ClassNotFoundException:没找到类 路径上的“android.view.fragment”:DexPathList [[zip文件 “/data/app/com.rankov.maplistener-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /系统/ lib中]]
在这一行
inflate(getContext(), R.layout.activity_maps, this);
这是我的xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.rankov.maplistener.MapsActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/abc_popup_background_mtrl_mult">
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
<Button
android:id="@+id/button_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:background="@drawable/abc_popup_background_mtrl_mult"
android:text="@string/done" />
</RelativeLayout>
</fragment>
这是我的观点
public class MapsView extends FrameLayout implements OnMapReadyCallback, PlaceSelectionListener, View.OnClickListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "qwe";
private Maps maps;
private SupportMapFragment mapFragment;
private GoogleApiClient mGoogleApiClient;
private PlaceAutocompleteFragment autocompleteFragment;
private Button button_done;
private Location userLocation;
public MapsView(Context context) {
super(context);
init();
}
private void init() {
inflate(getContext(), R.layout.activity_maps, this);
android.support.v4.app.FragmentActivity fragmentActivity = (android.support.v4.app.FragmentActivity) getContext();
FragmentManager fm = fragmentActivity.getSupportFragmentManager();
android.app.FragmentManager fm2 = fragmentActivity.getFragmentManager();
//mapFragment = (SupportMapFragment) (Object) findViewById(R.id.map);
mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
autocompleteFragment = (PlaceAutocompleteFragment)
fm2.findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(this);
mGoogleApiClient = new GoogleApiClient.Builder(getContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
button_done = (Button) findViewById(R.id.button_done);
button_done.setOnClickListener(this);
}
开始此活动
public class MapsActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_view);
//setContentView(R.layout.activity_maps);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.test_layout);
MapsView mView = new MapsView(getApplicationContext());
layout.addView(mView);
}
}
有什么问题?