不同 URL 打开相同

different URL opening the same

伙计们,在我的应用程序中,我构建了一个带有可扩展列表视图的菜单,其中一组有 4 个子项,一个打开 facebook 页面,另一个打开网站页面,一个 youtube 页面和一个 google+ 页面。但是无论我在哪里单击它们都会打开 google+ 页面,但我不明白为什么。这是代码:

public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            int pos = childPosition;
            //clique em contatos
            if(groupPosition == 5){
                switch(pos) {
                    //Clique em emails e contatos
                    case 0:
                        Intent i = new Intent(MainActivity.this, Contatos.class);
                        MainActivity.this.startActivity(i);
                }
            }
            //clique em hiperligacoes
            if(groupPosition == 3){
                switch(pos) {
                    //click no facebook
                    case 0:
                        Intent browserFace = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/moises.transporte.passageiros?fref=ts"));
                        startActivity(browserFace);
                    //click no site
                    case 1:
                        Intent browserSite = new Intent(Intent.ACTION_VIEW, Uri.parse("http://moises-transportes.pt/"));
                        startActivity(browserSite);
                    //click no youtube
                    case 2:
                        Intent browserYoutube = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/channel/UCXeHbISNnc0eLCPnTeolxLg"));
                        startActivity(browserYoutube);
                    //click no google+
                    case 3:
                        Intent browserGoogle = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/111005531753993560637/about"));
                        startActivity(browserGoogle);
                }
            }

你们能帮我看看为什么会这样吗?

你忘了在 switch 中打破你的案例。在为每个案例写下一个案例之前先写 break;。另外,添加一个默认案例。

break.

在每个 case 语句后使用 break。 Orelse 一个接一个地执行正确的情况后的所有情况。

     if(groupPosition == 3){


             switch(pos) {
                    //click no facebook
                    case 0:
                        Intent browserFace = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/moises.transporte.passageiros?fref=ts"));
                        startActivity(browserFace);
                        break;
                    //click no site
                    case 1:
                        Intent browserSite = new Intent(Intent.ACTION_VIEW, Uri.parse("http://moises-transportes.pt/"));
                        startActivity(browserSite);
                        break;
                    //click no youtube
                    case 2:
                        Intent browserYoutube = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/channel/UCXeHbISNnc0eLCPnTeolxLg"));
                        startActivity(browserYoutube);
                    //click no google+
                        break;
                    case 3:
                        Intent browserGoogle = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/111005531753993560637/about"));
                        startActivity(browserGoogle);
                        break;
                }
     }