Tengo varias activities, en una de ellas se encuentra un menú con diferentes botones y en las otras activities las cuales son del tipo tabbed, existen 3 fragments y en cada uno de estos fragments hay un WebView, hasta ahora he hecho que cada botón del menú me lleve a una activity diferente, pero necesito saber si se puede hacer que dependiendo del botón del menú que se haya oprimido se modifique la url de los WebView, para de esta forma no utilizar una activity por cada WebView y así ahorrar espacio.
este es el código del menú
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
LinearLayout contProgs;
ScrollView testWeb;
Button btnInformatica, btnBiologia, btnQuimica, btnMatematicas, btnFisica;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
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.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
contProgs=(LinearLayout)findViewById(R.id.contProgs);
btnInformatica=(Button)findViewById(R.id.btn_informatica);
btnBiologia=(Button)findViewById(R.id.btn_biologia);
btnQuimica=(Button)findViewById(R.id.btn_quimica);
btnMatematicas=(Button)findViewById(R.id.btn_matematicas);
btnFisica=(Button)findViewById(R.id.btn_fisica);
btnInformatica.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent InformaticiActivity = new Intent(MainActivity.this, InformaticaActivity.class);
startActivity(InformaticiActivity);
}
});
btnBiologia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent BologiiActivity = new Intent(MainActivity.this, BiologiaActivity.class);
startActivity(BologiiActivity);
}
});
btnQuimica.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent QuimiActivity = new Intent(MainActivity.this, QuimicaActivity.class);
startActivity(QuimiActivity);
}
});
btnMatematicas.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent MaterActivity = new Intent(MainActivity.this, MatematicasActivity.class);
startActivity(MaterActivity);
}
});
btnMatematicas.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent MaterActivity = new Intent(MainActivity.this, MatematicasActivity.class);
startActivity(MaterActivity);
}
});
btnFisica.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent FisisActivity = new Intent(MainActivity.this, FisicaActivity.class);
startActivity(FisisActivity);
}
});
}
este el código de la tabbed activity
public class InformaticaActivity extends AppCompatActivity implements
ActionBar.TabListener, ViewPager.OnPageChangeListener{
Button btn1;
WebView wView;
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_informatica);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
// Métodos de la interfaz ActionBar.TabListener
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
// Métodos de la interfaz ViewPager.OnPageChangeListener
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
getSupportActionBar().setSelectedNavigationItem(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment tabFragment = null;
switch (position){
case 0:
tabFragment = new FInformatica1();
break;
case 1:
tabFragment = new Finformatica2();
break;
case 2:
tabFragment = new Finforamtica3();
break;
}
return tabFragment;
}
@Override
public int getCount() {
// Show 2 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
String section = null;
switch (position) {
case 0:
section = "Aspectos generales";
break;
case 1:
section = "Talento humano";
break;
case 2:
section = "Plan de estudios";
break;
}
return section;
}
}
}
y este el código de un fragment
public class FInformatica1 extends Fragment {
Button btn1;
WebView wView;
TextView textView2;
ZoomControls zoomIt;
public FInformatica1() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_finformatica1, container, false);
String url = "file:///android_asset/nitro/informatica/indexInformatica.html";
WebView view = (WebView) rootView.findViewById(R.id.wView);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
return rootView;
}
}