Opening external website in android studio within a list item

Asked

Viewed 276 times

0

Good need to open an external link for example:

https:www.google.com

However it should stay within a litem of menu list (side menu). To open the Fragments I use the position of the item, there are 7 positions as quoted below.

@Override
public void onNavigationDrawerItemSelected(int position) {
    switch (position) {

    case 0:
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container, new FragmentListaRestaurantes_())
                .commit();
        break;

    case 1:
        getSupportFragmentManager().beginTransaction().addToBackStack(BACKSTACK)
                .replace(R.id.container, new FragmentFavoritos_())
                .commit();
        break;

    case 2:
        getSupportFragmentManager().beginTransaction().addToBackStack(BACKSTACK)
                .replace(R.id.container, new FragmentMeusPedidos_())
                .commit();
        break;

    case 3:
        getSupportFragmentManager().beginTransaction().addToBackStack(BACKSTACK)
                .replace(R.id.container, new FragmentMeusDados_()).commit();
        break;
    case 4:
        getSupportFragmentManager().beginTransaction().addToBackStack(BACKSTACK)
                .replace(R.id.container, new FragmentIndique()).commit();
            break;
    case 5:
            getSupportFragmentManager().beginTransaction().addToBackStack(BACKSTACK)
                    .replace(R.id.container, new FragmentIndique()).commit();
            break;
    case 6:
        sair();
        break;
    }
}

His position is 5.

My doubt is the following, I need to send it to any Fragment and redirect or I have to set the click directly from this case, calling a function that does this job ?

And how should I program this ?

  • I did not understand the question. No case can put the code you want.

1 answer

1


You want to send it to an external browser the application?

Do it this way:

case 5:
   String url = "http://www.google.com";
   Intent i = new Intent(Intent.ACTION_VIEW);
   i.setData(Uri.parse(url));
   startActivity(i);
break;
  • Brother worked perfectly, just what I wanted

Browser other questions tagged

You are not signed in. Login or sign up in order to post.