0

I a new to Android so pardon me if i ask something very basic. Can you please tell me how to make this fab button open url from these Strings

static {
    aniadirEntrada(new Lista_entrada("0", R.mipmap.ic_launcher, "BUHO", "http://google.com", "Búho es el nombre común de aves de la familia Strigidae, del orden de las estrigiformes o aves rapaces nocturnas. Habitualmente designa especies que, a diferencia de las lechuzas, tienen plumas alzadas que parecen orejas"));
    aniadirEntrada(new Lista_entrada("1", R.mipmap.ic_launcher, "COLIBRÍ", "http://google.com", "Los troquilinos (Trochilinae) son una subfamilia de aves apodiformes de la familia Trochilidae, conocidas vulgarmente como colibríes, quindes, tucusitos, picaflores, chupamirtos, chuparrosas, huichichiquis (idioma nahuatl), mainumby (idioma guaraní) o guanumby. Conjuntamente con las ermitas, que pertenecen a la subfamilia Phaethornithinae, conforman la familia Trochilidae que, en la sistemática de Charles Sibley, se clasifica en un orden propio: Trochiliformes, independiente de los vencejos del orden Apodiformes. La subfamilia Trochilinae incluye más de 100 géneros que comprenden un total de 330 a 340 especies."));

}

private static void aniadirEntrada(Lista_entrada entrada) {
    ENTRADAS_LISTA.add(entrada);
    ENTRADAS_LISTA_HASHMAP.put(entrada.id, entrada);
}



/**
 * Representa una entrada del contenido de la lista
 */
public static class Lista_entrada {
    public final String id;
    public final int idImagen;
    public final String textoEncima;
    public final String textoDebajo;
    public final String textoDebajolink;

    public Lista_entrada(String id,int idImagen, String textoEncima, String textoDebajo, String textoDebajolink) {
        this.id = id;
        this.idImagen = idImagen;
        this.textoEncima = textoEncima;
        this.textoDebajo = textoDebajo;
        this.textoDebajolink = textoDebajolink;
    }

This is my fab

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "This is fab", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
user3693698
  • 69
  • 2
  • 9
  • Possible duplicate of [How can I open a URL in Android's web browser from my application?](http://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application) – marcos E. Dec 28 '16 at 12:07

1 Answers1

0
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("yourUrl"));
        startActivity(intent);
    }
});
marcos E.
  • 477
  • 4
  • 11
  • I have a string this.textoDebajo = textoDebajo; how to parse that? – user3693698 Dec 28 '16 at 12:08
  • put the string containing the url you desire to open in the place of **yourUrl**, also check this for extra error handling http://stackoverflow.com/a/2201999/5810310 – marcos E. Dec 28 '16 at 12:09
  • You mean i should simply put texttoDebajo in place of "your url"? – user3693698 Dec 28 '16 at 12:14
  • check the link i put above, it is crashing because you dont have an app that captures the intent and handles the action view or your url is malformed(maybe its okey but u dont have **"http://" at the start**), you should read this for further info https://developer.android.com/guide/components/intents-filters.html?hl=es – marcos E. Dec 28 '16 at 12:21
  • I tried ".setText(mItem.textoDebajo);" but it still crashed – user3693698 Dec 28 '16 at 12:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/131703/discussion-between-marcos-e-and-user3693698). – marcos E. Dec 28 '16 at 12:25