不同的URL打开相同

时间:2015-07-26 19:58:52

标签: android url android-studio expandablelistview

所以,在我的应用程序中,我构建了一个菜单,其中包含一个expandablelistview,其中一个组有4个孩子,一个打开一个facebook页面,另一个是网站页面,一个youtube页面和一个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);
                }
            }

你们能帮助我找到为什么会这样吗?

2 个答案:

答案 0 :(得分:0)

你忘了在交换机中打破你的情况。在为每个案例编写下一个案例之前写下break;。此外,添加默认案例。

答案 1 :(得分:0)

break

在每个案例陈述后使用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;
                }
     }
相关问题