ViewPage - Change the icon on the text - java

I faced with a problem I can not solve. How can you replace icons in the text resource. Let's say instead of the first icons - current , the second icon - finished .
public class ViewPageAdapter extends FragmentPagerAdapter implements PagerSlidingTabStrip.CustomTabProvider {
private Context mContext;
private final int[] ICONS = {
R.drawable.selector_icon_active,
R.drawable.selector_icon_inactive
};
public ViewPageAdapter(FragmentManager fm, Context context) {
super(fm);
mContext = context;
}
#Override
public void tabUnselected(View view) {
view.setSelected(false);
}
#Override
public void tabSelected(View view) {
view.setSelected(true);
}
#Override
public View getCustomTabView(ViewGroup parent, int position) {
FrameLayout customLayout = (FrameLayout) LayoutInflater.from(mContext).inflate(R.layout.custom_tab, parent, false);
((ImageView) customLayout.findViewById(R.id.image)).setImageResource(ICONS[position]);
return customLayout;
}
#Override
public CharSequence getPageTitle(int position) {
// return null;
return super.getPageTitle(position);
}
#Override
public int getCount() {
return ICONS.length;
}
#Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
switch (position) {
case 0:
default:
bundle.putSerializable("TYPE", NotificationsType.ACTIVE);
break;
case 1:
bundle.putSerializable("TYPE", NotificationsType.INACTIVE);
break;
}
Fragment fragment = new TabFragment();
fragment.setArguments(bundle);
return fragment;
}
}

Related

position of tab not updating when it is removed

I am creating an application with dynamic tabs. I created tabs are able to add tabs by clicking a button and are able to remove from the back. But when I tried to remove the first tab, it is removed while after removing the first tab and tried to delete the last tab it is force closing with out-of-bounds exception.
I figure out the issue. Suppose there are 4 TABS and when I tried to delete the first tab 0th position tab (TAB 1) is deleted, now when I tried to delete the last tab say now the 4th TAB tab(now Supposedly 2nd position) it crashes as when I tried to log the position on deleting it shows the position as 3rd position.
ALl the deleting is done from viewPage adapter. and the code is :
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final ArrayList<Fragment> mFragmentList = new ArrayList<>();
private final ArrayList<String> mFragmentTitleList = new ArrayList<>();
Context context;
ViewPager viewPager;
TabLayout tabLayout;
int selectedTabPosition;
private boolean doNotifyDataSetChangedOnce = false;
public ViewPagerAdapter(FragmentManager manager, Context context, ViewPager viewPager,
TabLayout tabLayout) {
super(manager);
this.context = context;
this.viewPager = viewPager;
this.tabLayout = tabLayout;
}
#Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
#Override
public int getCount() {
if (doNotifyDataSetChangedOnce) {
doNotifyDataSetChangedOnce = false;
notifyDataSetChanged();
}
return mFragmentList.size();
}
public void addFrag(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
public void removeFrag(int position) {
Log.e("REMOVING POSITION ",String.valueOf(position));
Fragment fragment = mFragmentList.get(position);
mFragmentList.remove(fragment);
mFragmentTitleList.remove(position);
Log.e("mFragmentList_REMOVE",String.valueOf(mFragmentList.size()));
Log.e("TitleList_REMOVE",String.valueOf(mFragmentTitleList.size()));
removeTab(position);
//destroyFragmentView(viewPager, position, fragment);
notifyDataSetChanged();
}
public View getTabView(final int position) {
Log.e("mFragmentList",String.valueOf(mFragmentList.size()));
Log.e("TitleList",String.valueOf(mFragmentTitleList.size()));
View view = LayoutInflater.from(context).inflate(R.layout.custom_tab_item, null);
TextView tabItemName = (TextView) view.findViewById(R.id.textViewTabItemName);
CircleImageView tabItemAvatar =
(CircleImageView) view.findViewById(R.id.imageViewTabItemAvatar);
ImageButton remove = (ImageButton) view.findViewById(R.id.imageButtonRemove);
Log.e("getCount()-MAIN",String.valueOf(getCount()));
if(getCount() == 1){
remove.setVisibility(View.INVISIBLE);
}
else{
remove.setVisibility(View.VISIBLE);
}
ImageButton add = (ImageButton) view.findViewById(R.id.imageButtonAdd);
remove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("Remove", "Remove");
if(getCount() != 1){
removeFrag(position);
}
else{
// Toast.makeText("Atleast One Tab is requied")
}
}
});
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e("getCount()-ADD",String.valueOf(getCount()));
View view = LayoutInflater.from(context).inflate(R.layout.custom_tab_item, null);
ImageButton remove = (ImageButton) view.findViewById(R.id.imageButtonRemove);
if(getCount() == 1){
remove.setVisibility(View.INVISIBLE);
}
else{
remove.setVisibility(View.VISIBLE);
}
Bundle bundle = new Bundle();
bundle.putString("data", "POS"+position);
FragmentChild fragmentChild = new FragmentChild();
fragmentChild.setArguments(bundle);
addFrag(fragmentChild, "POS"+position);
notifyDataSetChanged();
if (getCount() > 0) tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(getCount() - 1);
setupTabLayout();
}
});
tabItemName.setText(mFragmentTitleList.get(position));
tabItemName.setTextColor(context.getResources().getColor(android.R.color.background_light));
tabItemAvatar.setImageResource(R.drawable.boy);
return view;
}
public void setupTabLayout() {
selectedTabPosition = viewPager.getCurrentItem();
for (int i = 0; i < tabLayout.getTabCount(); i++) {
tabLayout.getTabAt(i).setCustomView(getTabView(i));
}
}
public void destroyFragmentView(ViewGroup container, int position, Object object) {
FragmentManager manager = ((Fragment) object).getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.remove((Fragment) object);
trans.commit();
notifyDataSetChanged();
}
public void removeTab(int position) {
if (tabLayout.getChildCount() > 0 && tabLayout!=null) {
tabLayout.removeTabAt(position);
}
viewPager.setAdapter(this);
notifyDataSetChanged();
}
#Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
#Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
TAB STYLE:
Please help me to sort out this issue! what am i doing wrong here.I used a tutorial and done exactly as explained.
FINALLY FOUND A SOLUTION
if (getCount() > 0) tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(getCount() - 1);
setupTabLayout();
added this piece of code to removeFrag function!
public void removeFrag(int position) {
removeTab(position);
Log.e("REMOVING POSITION ",String.valueOf(position));
Fragment fragment = mFragmentList.get(position);
mFragmentList.remove(fragment);
mFragmentTitleList.remove(position);
Log.e("mFragmentList_REMOVE",String.valueOf(mFragmentList.size()));
Log.e("TitleList_REMOVE",String.valueOf(mFragmentTitleList.size()));
//destroyFragmentView(viewPager, position, fragment);
notifyDataSetChanged();
if (getCount() > 0) tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(getCount() - 1);
setupTabLayout();
}
Use this function to remove..this is happening because :-
The position of your getView(int position) is not updated after you are removing a tab.. so write the function of click listener of remove(imageButton) like this..
remove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("Remove", "Remove");
if(getCount() != 1){
remove.setEnabled(false); // it here..
removeFrag(position);
}
else{
// Toast.makeText("Atleast One Tab is requied")
}
}
});
public void removeFrag(int position) {
Log.e("REMOVING POSITION ",String.valueOf(position));
Fragment fragment = mFragmentList.get(position);
mFragmentList.remove(fragment);
mFragmentTitleList.remove(position);
Log.e("mFragmentList_REMOVE",String.valueOf(mFragmentList.size()));
Log.e("TitleList_REMOVE",String.valueOf(mFragmentTitleList.size()));
removeTab(position);
//destroyFragmentView(viewPager, position, fragment);
notifyDataSetChanged();
setupTabLayout(); // do the setup of tablayout after removing
}
Edit Do one more thing dont forget to disable the button.. because if the user clicks the button two consecutive times..in a flash the might crash..
remove.setEnabled(false); disable and enable again at getView(int position) again..
getView(int position)
{
........
remove.setEnabled(true); //enable
}
Update :-
public void removeTab(int position) {
if (tabLayout.getChildCount() > 0 && tabLayout!=null) {
tabLayout.removeTabAt(position);
//notifyDataSetChanged(); //notify here
removeTabPage(position);
}
//viewPager.setAdapter(this);
}
You also need to remove the page..
public void removeTabPage(int position) {
if (!mFragmentList.isEmpty() && position<mFragmentList.size()) {
mFragmentList.remove(position);
notifyDataSetChanged();
}
}
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final ArrayList<Fragment> mFragmentList = new ArrayList<>();
private final ArrayList<String> mFragmentTitleList = new ArrayList<>();
Context context;
ViewPager viewPager;
TabLayout tabLayout;
public ViewPagerAdapter(FragmentManager manager, Context context, ViewPager viewPager,
TabLayout tabLayout) {
super(manager);
this.context = context;
this.viewPager = viewPager;
this.tabLayout = tabLayout;
}
#Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
#Override
public int getCount() {
return mFragmentList.size();
}
public void addFrag(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
public void removeFrag(int position) {
removeTab(position);
Fragment fragment = mFragmentList.get(position);
mFragmentList.remove(fragment);
mFragmentTitleList.remove(position);
notifyDataSetChanged();
viewPager.setAdapter(this);
}
public View getTabView(final int position) {
View view = LayoutInflater.from(context).inflate(R.layout.custom_tab_item, null);
TextView tabItemName = (TextView) view.findViewById(R.id.textViewTabItemName);
CircleImageView tabItemAvatar =
(CircleImageView) view.findViewById(R.id.imageViewTabItemAvatar);
ImageButton remove = (ImageButton) view.findViewById(R.id.imageButtonRemove);
remove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("Remove", "Remove");
removeFrag(position);
}
});
tabItemName.setText(mFragmentTitleList.get(position));
tabItemName.setTextColor(context.getResources().getColor(android.R.color.background_light));
switch (mFragmentTitleList.get(position)) {
case "Gaiduk":
tabItemAvatar.setImageResource(R.drawable.gaiduk);
break;
case "Nguyen":
tabItemAvatar.setImageResource(R.drawable.avatar);
break;
case "Balakin":
tabItemAvatar.setImageResource(R.drawable.balakin);
break;
case "Golovin":
tabItemAvatar.setImageResource(R.drawable.golovin);
break;
case "Ovcharov":
tabItemAvatar.setImageResource(R.drawable.ovcharov);
break;
case "Solovienko":
tabItemAvatar.setImageResource(R.drawable.solovei);
break;
default:
tabItemAvatar.setImageResource(R.drawable.boy);
break;
}
return view;
}
public void removeTab(int position) {
if (tabLayout.getChildCount() > 0) {
tabLayout.removeTabAt(position);
}
}
#Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
#Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
Added removeFrag function as:
public void removeFrag(int position) {
removeTab(position);
Log.e("REMOVING POSITION ",String.valueOf(position));
Fragment fragment = mFragmentList.get(position);
mFragmentList.remove(fragment);
mFragmentTitleList.remove(position);
Log.e("mFragmentList_REMOVE",String.valueOf(mFragmentList.size()));
Log.e("TitleList_REMOVE",String.valueOf(mFragmentTitleList.size()));
//destroyFragmentView(viewPager, position, fragment);
notifyDataSetChanged();
if (getCount() > 0) tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(getCount() - 1);
setupTabLayout();
}

How to refresh fragment in FragmentPagerAdapter

I Have 4 Fragments in 1 Activity. I need to make sure that on every fragment change the fragment is refreshed because I load JSON Data in every fragment. I use FragmentPager Adapter and RecyclerView to Show Data
This is my Adapter ( SickAdapter.java ) the code :
public class SickAdapter extends FragmentPagerAdapter{
private static final String TAG = SickAdapter.class.getSimpleName();
private static final int FRAGMENT_COUNT = 4;
public SickAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position){
case 0:
return new SickFragmentToAll();
case 1:
return new SickFragmentToPending();
case 2:
return new SickFragmentToApproved();
case 3:
return new SickFragmentToDenied();
}
return null;
}
#Override
public int getCount() {
return FRAGMENT_COUNT;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0:
return "All";
case 1:
return "Pending";
case 2:
return "Approved";
case 3:
return "Denied";
}
return null;
}
}
In my Class ( SickClass.java ) I create SickClass and I Call SickAdapter, I explode them, and this is my Code :
public class SickClass extends Fragment {
private static final String TAG = SickClass.class.getSimpleName();
private SickAdapter mAdapter;
private TabLayout tabLayout;
private ViewPager viewPager;
public SickClass() {
}
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.employee_leave_class, container, false);
tabLayout = (TabLayout)view.findViewById(R.id.tabs);
viewPager = (ViewPager)view.findViewById(R.id.view_pager);
if(mAdapter == null) {
mAdapter = new SickAdapter(getChildFragmentManager());
}
viewPager.setAdapter(new SickAdapter(getChildFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(1, true);
tabLayout.post(new Runnable() {
#Override
public void run() {
tabLayout.setupWithViewPager(viewPager);
}
});
return view;
}
}
Try below code for reload your fragment;
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(YOUR_FRAGMENT_NAME.this).attach(YOUR_FRAGMENT_NAME.this).commit();
You can use startActivityForResult() to get the result from the activity.
References:
ViewPager PagerAdapter not updating the View
How to refresh a Fragment of a FragmentPagerAdapter?

ViewPager get fragment reference

I have activity where I have created a viewpager that contains two fragments. I need to get a reference to the existing fragment or it's view, in the activity to refresh the list from the fragment if necessary. I was looking for a solution for two days, but found nothing on this occasion.
So here is my adapter
public class SearchPagerAdapter extends FragmentStatePagerAdapter {
CharSequence Titles[];
int NumbOfTabs;
public SearchPagerAdapter(FragmentManager fm,CharSequence mTitles[], int mNumbOfTabsumb) {
super(fm);
this.Titles = mTitles;
this.NumbOfTabs = mNumbOfTabsumb;
}
#Override
public Fragment getItem(int position) {
if(position == 0)
{
FragmentAyahSearch tab1 = new FragmentAyahSearch();
return tab1;
}
else
{
FragmentSurahList tab2 = new FragmentSurahList();
return tab2;
}
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
}
#Override
public CharSequence getPageTitle(int position) {
return Titles[position];
}
#Override
public int getCount() {
return NumbOfTabs;
}
}
below, I create a viewpager and adapter in MainActivity
searchAdapter = new SearchPagerAdapter(getSupportFragmentManager(), searchTitles, Numboftabs);
pager.setAdapter(searchAdapter);
tabs.setViewPager(pager);
I hope you will help me, because I'm losing my mind over this.
I would suggest maintain a list like
private List<Fragment> frag = new ArrayList<Fragment>();
then
public class SearchPagerAdapter extends FragmentStatePagerAdapter {
CharSequence Titles[];
int NumbOfTabs;
public SearchPagerAdapter(FragmentManager fm,CharSequence mTitles[], int mNumbOfTabsumb) {
super(fm);
this.Titles = mTitles;
this.NumbOfTabs = mNumbOfTabsumb;
}
#Override
public Fragment getItem(int position)
{
Fragment fragment = frag.get(position);
if(fragment == null )
{
if (position == 0)
{
fragment = new FragmentAyahSearch();
}
else
{
fragment = new FragmentSurahList();
}
}
return fragment;
}
#Override
public CharSequence getPageTitle(int position) {
return Titles[position];
}
#Override
public int getCount() {
return frag.size();
}
now if you want the reference of any fragment
just call , frag.get(<position>) will return you desire frgament

how to jump to Fragment upon selection of respective tab bar

//SampleTabsWithIcons.java
public class SampleTabsWithIcons extends FragmentActivity {
private static final int[] ICONS = new int[] {
R.drawable.events,
R.drawable.rss,
R.drawable.user,
R.drawable.bell,
R.drawable.search
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.simple_tabs);
FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager());
ViewPager pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(adapter);
TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);
}
class GoogleMusicAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
public GoogleMusicAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return TestFragment.newInstance(ICONS[position % ICONS.length]);
}
#Override public int getIconResId(int index) {
return ICONS[index];
}
#Override
public int getCount() {
return ICONS.length;
}
}
}
//TestFragment.java
public final class TestFragment extends Fragment {
private static final String KEY_CONTENT = "TestFragment:Content";
public static TestFragment newInstance(int icons) {
TestFragment fragment = new TestFragment();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 20; i++) {
builder.append(icons).append(" ");
}
builder.deleteCharAt(builder.length() - 1);
fragment.mContent = builder.toString();
return fragment;
}
private String mContent = "???";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
mContent = savedInstanceState.getString(KEY_CONTENT);
}
}
#SuppressWarnings("deprecation")
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
TextView text = new TextView(getActivity());
text.setGravity(Gravity.CENTER);
text.setText(mContent);
text.setTextSize(20 * getResources().getDisplayMetrics().density);
text.setPadding(20, 20, 20, 20);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(text);
return layout;
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(KEY_CONTENT, mContent);
}
}
//TestFragmentAdapter.java
class TestFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
private static final int[] ICONS = new int[] {
R.drawable.events,
R.drawable.rss,
R.drawable.user,
R.drawable.bell,
R.drawable.search
};
private int mCount = ICONS.length;
public TestFragmentAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return TestFragment.newInstance(ICONS[position % ICONS.length]);
}
#Override
public int getCount() {
return mCount;
}
#Override
public int getIconResId(int index) {
return ICONS[index % ICONS.length];
}
public void setCount(int count) {
if (count > 0 && count <= 10) {
mCount = count;
notifyDataSetChanged();
}
}
}
and my output is,
My question is instead of displaying numbers while selecting each tabs, I want to go to new fragment activity (ie, newpage.java). Now some numbers are showing on each tab selection. How can i implement this.
I have 5 class (first.java,second.java,third.java,four.java,five.java) and 5 layout for each tabs (first.xml... respectively)
I tried a lot but no success. Does anyone know the answer.
Thanks.
Ok you can make your own Fragments and then return them in the getItem(int position); for example, you could have an array of your Fragments calendar, feed, etc. then on each position you return one.
//SampleTabsWithIcons.java
Fragment[] tabFragments = new Fragment[] {CalendarFragment.newInstance(),
FeedFragment.newInstance()}
.....
#Override
public Fragment getItem(int position) {
return tabFragments[position];
}
You can simply use this and set the tab to the viewPager ...
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
viewPager.setCurrentItem(tab.getPosition());
}
Inside fragment pager adapter you can do like this.
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
frag = UsageRecoSummaryFragemrent.newInstance(position);
// changeColor(newColor);
break;
Inside fragment
public static UsageRecoSummaryFragemrent newInstance(int position) {
UsageRecoSummaryFragemrent f = new UsageRecoSummaryFragemrent();
Bundle b = new Bundle();
b.putInt(ARG_POSITION, 0);
f.setArguments(b);
return f;
}

Please help me with Instance

I have two buttons "start hotel1" and "start hotel2".
when you click on them, I create a fragment in which ViewPager:
public class PagerContainer extends Fragment {
static final int PAGE_COUNT = 2;
private String hotel;
public PagerContainer(String hotel) {
this.hotel = hotel;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.pager_container, null);
ViewPager pager = (ViewPager) v.findViewById(R.id.pager);
PagerAdapter pagerAdapter = new MyFragmentPagerAdapter(getActivity().getSupportFragmentManager());
pager.setAdapter(pagerAdapter);
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
Log.d("LOG", "onPageSelected, position = " + position);
}
#Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
return v;
}
private class MyFragmentPagerAdapter extends FragmentPagerAdapter {
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return CalendarView.newInstance(position,hotel);
}
#Override
public int getCount() {
return PAGE_COUNT;
}
#Override
public CharSequence getPageTitle(int position) {
return "title";
}
}
}
I load it in another fragment that takes different parameters, depending on the button:
public class CalendarView extends Fragment {
static final String ARGUMENT_PAGE_NUMBER = "arg_page_number";
static final String ARGUMENT_HOTEL = "arg_hotel";
private int pageNumber;
private String hotel;
static CalendarView newInstance(int page,String hotel) {
Log.d("myLOG","newInstance");
CalendarView calendarView = new CalendarView();
Bundle arguments = new Bundle();
arguments.putInt(ARGUMENT_PAGE_NUMBER, page);
arguments.putString(ARGUMENT_HOTEL, hotel);
calendarView.setArguments(arguments);
return calendarView;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.calendar, null);
pageNumber = getArguments().getInt(ARGUMENT_PAGE_NUMBER);
hotel = getArguments().getString(ARGUMENT_HOTEL);
...
return v;
}
public class NewThread extends AsyncTask<String, Void, String> {
protected String doInBackground(String... strings) {
...
}
#Override
protected void onPostExecute(String s) {
....
}
}
}
First pressing any key data normally loaded. After they loaded I click on the second button, and I have an empty screen. Log just says that the instance is not created. I need something to clean or rebuild? how?
case CONFEENCE_GRUP_NODE:
Fragment conference;
switch (position2) {
case HOLIDAY:
conference = new PagerContainer("holiday");
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
fragmentManager.beginTransaction().replace(R.id.content_frame, conference).commit();
break;
case CITY:
conference = new PagerContainer("city");
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
fragmentManager.beginTransaction().replace(R.id.content_frame, conference).commit();
break;
}
break;
Don't ever override the Fragment constructor, because they MUST have an empty constructor. Create the same newInstance method in your PagerContainer, and grab the parameter from it:
private static final String ARGUMENT_PAGE_HOTEL = "arg_page_hotel";
public PagerContainer() {
}
public static PagerContainer newInstance(String hotel) {
PagerContainer container = new PagerContainer();
Bundle arguments = new Bundle();
arguments.putString(ARGUMENT_PAGE_HOTEL, hotel);
container.setArguments(arguments);
return container;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.pager_container, null);
hotel = getArguments().getString(ARGUMENT_PAGE_HOTEL);
...
return v;
}

Categories

Resources