quisiera abrir una url con un botón que se encuentra alojado en un fragment,la idea es colocar un botón en cada fragment y que cada botón me lleve a una url distinta.
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_id);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
FragmentManager fragmentManager=getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.contenedor,new InteligensaFragment()).commit();
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private Button btn;
private Uri url;
public void onClick(View v){
switch (v.getId()){
case R.id.inteligensaurl:
url=Uri.parse("https://www.inteligensa.com/");
btn=(Button)findViewById(R.id.inteligensaurl);
btn.setOnClickListener(this);
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
Fragment myfragment = null;
boolean fragmentSeleccionado = false;
String tittle ="";
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.background);
ImageView imageView = (ImageView) findViewById(R.id.imageView4);
TextView textView = (TextView) findViewById(R.id.textViewt);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_id);
if (id == R.id.nav_inteligensa) {
myfragment = new InteligensaFragment();
fragmentSeleccionado = true;
tittle="INTELIGENSA";
linearLayout.setBackgroundResource(R.drawable.material_design);
imageView.setImageResource(R.drawable.web_hi_res_512);
textView.setText("Inteligensa");
} else if (id == R.id.nav_inteliseño) {
myfragment = new InteliSenoFragment();
fragmentSeleccionado = true;
tittle="INTELISEÑO";
linearLayout.setBackgroundResource(R.drawable.inteliseno);
imageView.setImageResource(R.drawable.web_hi_res_512);
textView.setText("Inteliseño");
} else if (id == R.id.nav_intelitec) {
myfragment = new InteliTecFragment();
fragmentSeleccionado = true;
tittle="INTELITEC";
linearLayout.setBackgroundResource(R.drawable.intelitecfondo2);
imageView.setImageResource(R.drawable.logo_intelitec);
textView.setText("Intelitec");
} else if (id == R.id.nav_intelifon) {
myfragment = new InteliFoneFragment();
fragmentSeleccionado = true;
tittle="INTELIFON";
textView.setText("InteliFon");
} else if (id == R.id.nav_intelipunto) {
myfragment = new InteliPuntoFragment();
fragmentSeleccionado = true;
tittle="INTELIPUNTO";
textView.setText("InteliPunto");
} else if (id == R.id.nav_intelisoft) {
myfragment = new InteliSoftFragment();
fragmentSeleccionado = true;
tittle="INTELISOFT";
textView.setText("InteliSoft");
}
if(fragmentSeleccionado==true){
getSupportFragmentManager().beginTransaction().replace(R.id.contenedor, myfragment).commit();
getSupportActionBar().setTitle(tittle);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
Al momento de construir el evento onclick me crea salta este error