Я вкладки деятельности с 1 фрагментом, этот фрагмент имеет кнопку, я хочу, когда я нажимаю кнопку это создать новый фрагмент и я могу ударить между двумя фрагментамидобавить фрагмент к пейджеру адаптеру на кнопке мыши
это основной вид деятельности
public class ActivityBeamRec extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
public static CustomViewPager mViewPager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_beam_rec);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (CustomViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setPagingEnabled(false);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0 : return PlaceholderFragment.newInstance(position + 1);
// case 1 : return the new fragment ;
}
return null;
}
@Override
public int getCount() {
return 1 ;
}
}
}
Это фрагмент, который у меня есть.
public class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_activity_beam_rec, container, false);
final EditText etxb;
etxb = (EditText)rootView.findViewById(R.id.editText);
final Button buDesign = (Button)rootView.findViewById(R.id.buDesign);
buDesign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double b;
b = Double.valueOf(etxb.getText().toString());
\\here i want the button to create the second fragment and pass the variable d to it
ActivityBeamRec.mViewPager.setPagingEnabled(true); // this is to enable the siwpe between the fragments
ActivityBeamRec.mViewPager.setCurrentItem(2); // ths is to set the new fragment as the current view
}
});
return rootView;
}
}
второй фрагмент должен пройти на создание вида сцены после нажатия кнопки, и, пожалуйста, где я ставлю каждый код, если есть способ сделать это.
жаль, что я новичок в Java, мой секции пейджера адаптер находится в основной деятельности 'частного SectionsPagerAdapter mSectionsPagerAdapter; 'Как я могу добавить код? –
Добавлен код MainActivity – Automatik