我希望在活动加载完成后自动点击一个片段。
片段定义如下:
我尝试过这样做。
片段定义如下:
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>
我尝试过这样做。
fragment = findViewById(R.id.place_autocomplete_fragment);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
fragment.performClick();
}
}, 1000);
但它没有起作用。
有没有自动点击片段的方法?
编辑: 在我的情况下,该片段是由以下方式膨胀的
//PlaceAutoComplete Search Implementation
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Log.i(String.valueOf(this), "Place: " + place.getName() + "\nID: " + place.getId());
String placeId = place.getId();
try {
Intent intent = new Intent(PlaceSearch.this, PlaceDetailsFromSearch.class);
Bundle extras = new Bundle();
extras.putString("placeID", placeId);
intent.putExtras(extras);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onError(Status status) {
Log.i(String.valueOf(this), "An error occurred: " + status);
}
});