, , , , https://github.com/jacktech24/pager-sliding-strip-example
-, , , , .. mTabs :
mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
private class TestAdapter extends FragmentPagerAdapter {
private ArrayList<String> tabs = new ArrayList<>();
public TestAdapter(FragmentManager supportFragmentManager) {
super(supportFragmentManager);
}
@Override
public Fragment getItem(int position) {
Fragment frag = new ExampleFragment();
Bundle bundle = new Bundle();
bundle.putString("title", (String) getPageTitle(position));
frag.setArguments(bundle);
return frag;
}
@Override
public CharSequence getPageTitle(int position) {
return tabs.get(position);
}
@Override
public int getCount() {
return tabs.size();
}
public void addTab(String tab) {
tabs.add(tab);
notifyDataSetChanged();
mTabs.notifyDataSetChanged();
}
public void removeTab(int position) {
tabs.remove(position);
notifyDataSetChanged();
mTabs.notifyDataSetChanged();
}
}
, :
mAdapter.addTab("test 1");
mAdapter.addTab("test 2");
mAdapter.addTab("test 3");
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAdapter.addTab("test "+(mAdapter.getCount()+1));
}
});