private void initData() {
fragmentManager = getSupportFragmentManager();
fragment1 = new Fragment1();
fragment2 = new Fragment2();
fragment3 = new Fragment3();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.main_linearLayout, fragment1, "fragment1");
fragmentTransaction.add(R.id.main_linearLayout, fragment2, "fragment2");
fragmentTransaction.add(R.id.main_linearLayout, fragment3, "fragment3");
fragmentTransaction.show(fragment1);
//fragmentTransaction.hide(fragment2);
// fragmentTransaction.hide(fragment3);
fragmentTransaction.commit();
}
private void initView() {
textView1 = (TextView) findViewById(R.id.text_1);
textView2 = (TextView) findViewById(R.id.text_2);
textView3 = (TextView) findViewById(R.id.text_3);
textView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cutFragment(fragment1, fragment2, fragment3);
}
});
textView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cutFragment(fragment2, fragment1, fragment3);
}
});
textView3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cutFragment(fragment3, fragment1, fragment2);
}
});
}
private void cutFragment(Fragment fragment1, Fragment fragment2, Fragment fragment3) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.show(fragment1);
transaction.hide(fragment2);
transaction.hide(fragment3);
transaction.commit();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)