- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 fragment 导航问题。我使用 GoogleMap 制作了一个带有 fragment 的 MainActivity。使用 NavigationDrawer,我选择转到 GoogleMapFragment,它可以工作,但如果我更改 fragment ,并想返回到我已经启动的 GoogleMapFragment,它会崩溃。
登录目录:
04-24 18:03:19.576: D/OpenGLRenderer(1165): Enabling debug mode 0
04-24 18:03:23.354: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.364: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.374: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.384: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.384: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.404: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.415: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.415: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.424: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.454: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.454: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.465: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.474: W/GooglePlayServicesUtil(1165): Google Play services is missing.
04-24 18:03:23.484: W/System.err(1165): java.lang.NullPointerException
04-24 18:03:23.484: W/System.err(1165): at app.findme.map.MainActivity$GoogleMapFragment.initilizeMap(MainActivity.java:261)
04-24 18:03:23.484: W/System.err(1165): at app.findme.map.MainActivity$GoogleMapFragment.onCreateView(MainActivity.java:244)
04-24 18:03:23.494: W/System.err(1165): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:828)
04-24 18:03:23.494: W/System.err(1165): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
04-24 18:03:23.494: W/System.err(1165): at android.app.BackStackRecord.run(BackStackRecord.java:622)
04-24 18:03:23.494: W/System.err(1165): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
04-24 18:03:23.494: W/System.err(1165): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
04-24 18:03:23.504: W/System.err(1165): at android.os.Handler.handleCallback(Handler.java:605)
04-24 18:03:23.504: W/System.err(1165): at android.os.Handler.dispatchMessage(Handler.java:92)
04-24 18:03:23.504: W/System.err(1165): at android.os.Looper.loop(Looper.java:137)
04-24 18:03:23.504: W/System.err(1165): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-24 18:03:23.514: W/System.err(1165): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 18:03:23.514: W/System.err(1165): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 18:03:23.514: W/System.err(1165): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-24 18:03:23.524: W/System.err(1165): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-24 18:03:23.524: W/System.err(1165): at dalvik.system.NativeStart.main(Native Method)
04-24 18:03:27.805: D/dalvikvm(1165): GC_CONCURRENT freed 186K, 3% free 9287K/9543K, paused 8ms+6ms
04-24 18:03:29.425: D/AndroidRuntime(1165): Shutting down VM
04-24 18:03:29.425: W/dalvikvm(1165): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-24 18:03:29.455: E/AndroidRuntime(1165): FATAL EXCEPTION: main
04-24 18:03:29.455: E/AndroidRuntime(1165): android.view.InflateException: Binary XML file line #11: Error inflating class fragment
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-24 18:03:29.455: E/AndroidRuntime(1165): at app.findme.map.MainActivity$GoogleMapFragment.onCreateView(MainActivity.java:240)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:828)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.app.BackStackRecord.run(BackStackRecord.java:622)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.os.Handler.handleCallback(Handler.java:605)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.os.Handler.dispatchMessage(Handler.java:92)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.os.Looper.loop(Looper.java:137)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-24 18:03:29.455: E/AndroidRuntime(1165): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 18:03:29.455: E/AndroidRuntime(1165): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 18:03:29.455: E/AndroidRuntime(1165): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-24 18:03:29.455: E/AndroidRuntime(1165): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-24 18:03:29.455: E/AndroidRuntime(1165): at dalvik.system.NativeStart.main(Native Method)
04-24 18:03:29.455: E/AndroidRuntime(1165): Caused by: java.lang.IllegalArgumentException: Binary XML file line #11: Duplicate id 0x7f050008, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.app.Activity.onCreateView(Activity.java:4248)
04-24 18:03:29.455: E/AndroidRuntime(1165): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
04-24 18:03:29.455: E/AndroidRuntime(1165): ... 18 more
04-24 18:03:30.165: I/dalvikvm(1165): threadid=3: reacting to signal 3
04-24 18:03:30.185: I/dalvikvm(1165): Wrote stack traces to '/data/anr/traces.txt'
04-24 18:05:47.835: I/dalvikvm(1212): threadid=3: reacting to signal 3
04-24 18:05:47.916: I/dalvikvm(1212): Wrote stack traces to '/data/anr/traces.txt'
04-24 18:05:48.085: D/libEGL(1212): loaded /system/lib/egl/libGLES_android.so
04-24 18:05:48.105: D/libEGL(1212): loaded /system/lib/egl/libEGL_emulation.so
04-24 18:05:48.105: D/(1212): HostConnection::get() New Host Connection established 0x1d2f90, tid 1212
04-24 18:05:48.155: D/libEGL(1212): loaded /system/lib/egl/libGLESv1_CM_emulation.so
04-24 18:05:48.155: D/libEGL(1212): loaded /system/lib/egl/libGLESv2_emulation.so
04-24 18:05:48.225: W/EGL_emulation(1212): eglSurfaceAttrib not implemented
04-24 18:05:48.235: D/OpenGLRenderer(1212): Enabling debug mode 0
04-24 18:05:48.335: I/dalvikvm(1212): threadid=3: reacting to signal 3
04-24 18:05:48.356: I/dalvikvm(1212): Wrote stack traces to '/data/anr/traces.txt'
主要 Activity :
package app.track.map;
import java.util.Locale;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.SearchManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mPlanetTitles;
// Google Map
private GoogleMap googleMap;
private static String SelectedMenuPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = mDrawerTitle = getTitle();
mPlanetTitles = getResources().getStringArray(R.array.drawer_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// enable ActionBar app icon to behave as action to toggle nav drawer
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
selectItem(0);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.map, menu);
return super.onCreateOptionsMenu(menu);
}
/* Called whenever we call invalidateOptionsMenu() */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content view
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action buttons
switch(item.getItemId()) {
case R.id.action_websearch:
// create intent to perform web search for this planet
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, getActionBar().getTitle());
// catch event that there's no activity to handle intent
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/* The click listner for ListView in the navigation drawer */
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
private void selectItem(int position) {
SelectedMenuPosition = getResources().getStringArray(R.array.drawer_array)[position];
// update the main content by replacing fragments
if ( position == 2){
Fragment fragment = new GoogleMapFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
else if( position == 3){
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
else
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(SelectedMenuPosition.equals("Navigate")){
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
return true;
}
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
return true;
}
}
return super.onKeyDown(keyCode, event);
}
public static class GoogleMapFragment extends Fragment {
// Google Map
private GoogleMap googleMap;
public GoogleMapFragment() {
// Empty constructor required for fragment subclasses
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_map, container, false);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
getActivity().setTitle(SelectedMenuPosition);
return rootView;
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setRotateGesturesEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.setMyLocationEnabled(true);
LatLng sydney = new LatLng(-33.867, 151.206);
googleMap.setMyLocationEnabled(true);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
googleMap.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
// check if map is created successfully or not
if (googleMap == null) {
//Toast.makeText(getApplicationContext(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
}
}
}
}
}
谷歌地图 View :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
提前致谢
最好的问候。
最佳答案
您应该覆盖此方法:(它会在您点击另一个 fragment 后正确销毁 google_map_fragment ..)
public void onDestroyView()
{
super.onDestroyView();
Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}
如果你想每次都初始化 map fragment ,你也必须覆盖这个方法:)
@Override
public void onPause(){
super.onPause();
if(googleMap != null) {
googleMap = null;
{
}
关于android - 单击两次或更改 fragment 时,Google map fragment 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23316426/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!