-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyAdapter.java
55 lines (44 loc) · 1.56 KB
/
MyAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.example.dell.aryashitlist;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import java.util.ArrayList;
/**
* Created by kriti on 05-01-2017.
*/
public class MyAdapter extends FragmentStatePagerAdapter {
private final ArrayList<Fragment> mFragmentList = new ArrayList<>();
private final ArrayList<String> mFragmentTitleList = new ArrayList<>();
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
public void addFrag(Fragment fragment, String name) {
mFragmentList.add(fragment);
mFragmentTitleList.add(name);
}
public void removeFrag(int position){
Fragment fragment = mFragmentList.get(position);
mFragmentList.remove(position);
mFragmentTitleList.remove(position);
destroyFragmentView(fragment);
}
public void destroyFragmentView(Object object) {
FragmentManager manager = ((Fragment) object).getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.remove((Fragment) object);
trans.commit();
}
}