繁体   English   中英

MapView中的菜单可返回到WebView中的特定网址

[英]Menu in MapView to return to a specific url in a WebView

我的FriendApp中有以下菜单,该菜单使用Intent来调用MapView。 当我到达FriendMaps时,我重新创建了菜单,但是现在想知道是否可以返回到Webview中的其他页面-我通过使用loadUrl()在webview菜单中完成此操作; 但不确定如何从地图视图中执行此操作。

FriendApp菜单:

    @Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case FRIENDS:
        mWebView.loadUrl("http://example.com/myfrienddash2.php");
        return true;
    case MAP:
        Intent friendMap = new Intent(FriendApp.this, FriendMaps.class);
        startActivity(friendMap);
        return true;
    case SEARCH:
        mWebView.loadUrl("http://example.com/myfrienddash3.php");
        return true;
    case INFO:
        mWebView.loadUrl("http://example.com/myfrienddash4.php");
        return true;
    case QUIT:
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

然后,在FriendMaps中,我只是模仿该菜单,但需要弄清楚如何返回到不同的页面,而不是仅仅加载Webview的“主页”。

FriendMaps菜单:

    @Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case FRIENDS:
        Intent friendApp = new Intent(FriendMaps.this, FriendApp.class);
        startActivity(friendApp);
        return true;
    case MAP:
        return true;
    case SEARCH:
        Intent friendApp2 = new Intent(FriendMaps.this, FriendApp.class);
        startActivity(friendApp2);
        return true;
    case INFO:
        Intent friendApp3 = new Intent(FriendMaps.this, FriendApp.class);
        startActivity(friendApp3);
        return true;
    case QUIT:
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

因此,我需要弄清楚如何使地图菜单像第一个菜单一样工作。

不知道这是否是“最佳”方法,但是我发现了它,并且效果很好。 在我的地图菜单中,当我创建Intent时,我正在放置数据以标识其来源,然后在Friend活动中,我管理哪种情况开始了活动并相应地显示。

IE浏览器:

Intent friendApp = new Intent(FriendMaps.this, FriendApp.class);
Bundle b = new Bundle();
b.putString("SEARCH", "search data");
friendApp.putExtras(b);
startActivity(friendApp);

需要注意的一件事是,我必须在FriendApp中进行一些null管理,以确保使用getString时不会出现nullexception。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM