Ejemplo n.º 1
0
 // TODO: Rename and change types and number of parameters
 public static CardsFragment newInstance(String mTitle, String param2) {
   CardsFragment fragment = new CardsFragment();
   Bundle args = new Bundle();
   args.putString(ARG_PARAM1, mTitle);
   args.putString(ARG_PARAM2, param2);
   fragment.setArguments(args);
   return fragment;
 }
Ejemplo n.º 2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_cards, container, false);

    final FloatingActionButton btn = (FloatingActionButton) rootView.findViewById(R.id.btn);
    btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getActivity(), CoordinatorLayoutActivity.class);

            Bundle bundle = new Bundle();
            // bundle.putString("name", "杭州公交卡");
            // bundle.putString("number", "1111111111111111111");
            // intent.putExtra("data", bundle);
            intent.putExtra("cardInfo", new CardInfo("杭州公交卡", "1111111111111111111"));

            // startActivity(intent);
            startActivityForResult(intent, 0);
          }
        });
    ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
    //        TextView txtCard=(TextView) rootView.findViewById(R.id.txtCard);
    //        txtCard.setText(mTitle);

    TabLayout tabs = (TabLayout) rootView.findViewById(R.id.tablayout);
    tabs.addTab(tabs.newTab().setText("Tab1"));
    tabs.addTab(tabs.newTab().setText("Tab2"));
    tabs.addTab(tabs.newTab().setText("Tab3"));
    tabs.addTab(tabs.newTab().setText("Tab4"));
    tabs.addTab(tabs.newTab().setText("Tab5"));
    tabs.addTab(tabs.newTab().setText("Tab6"));
    List<String> titles = new ArrayList<>();
    List<Fragment> fragments = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
      String title = "Tab" + (i + 1);
      tabs.addTab(tabs.newTab().setText(title));
      titles.add(title);
      Fragment fragment = CardsFragment.newInstance(title, title);
      fragments.add(fragment);
    }

    cardFragmentAdapter mAdapter =
        new cardFragmentAdapter(getActivity().getSupportFragmentManager(), titles, fragments);
    viewPager.setAdapter(mAdapter);
    tabs.setupWithViewPager(viewPager);
    tabs.setTabsFromPagerAdapter(mAdapter);

    return rootView;
  }