How to place url from my web to a FAB

-1

I add my code:

public class Main extends AppCompatActivity {

    private RecyclerView mBlogList;
    FirebaseDatabase database;
    DatabaseReference myRef;

    private BottomNavigationView bottomNavigationView;

    WebView browser = (WebView) findViewById(R.id.activity_main_webview);

    FloatingActionButton miFab = (FloatingActionButton) findViewById(R.id.myFAB);

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notification);

        miFab.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //Abre webview
                browser.loadUrl("http://www.google.com");
            }
        });
}

I need to assign an Url, to the FAB, to open the webview, that FAB button is inside a Recycle View.

    
asked by Elihat Caceres 03.01.2017 в 23:27
source

2 answers

0

Try the following:

 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.notification);

  //Verifica que tu id activity_main_webview este declarado en tu layout notification
  WebView browser = (WebView) findViewById(R.id.activity_main_webview);

  FloatingActionButton miFab = (FloatingActionButton) findViewById(R.id.miFab); 
  miFab.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
       //Abre webview
       browser.loadUrl("https://www.google.com");
     } 
  });
}

or you can also try adding within the onClick

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("tu_Url"));
    startActivity(intent);

Note: Remember to add to your URL link or link

    
answered by 03.01.2017 / 23:45
source
0

This was what I told you in the question:

Place a link in an Android cardview connected to the database in Firebase

simply add a OnClickListener to the button:

myFloatingButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    String url = "https://stackoverflow.com";
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    startActivity(i);
                }
            });
    
answered by 04.01.2017 в 00:11