LayoutManager for Recyclerview with different cell spancount - xamarin

I am working to achieve a recycler view interface that looks like this:
Presently, am only using a recyclerview with LinearLayoutManager using an adapter with two viewholders, i tried gridLayout manager too but i did not achieve the target interface: I need help achieving this, Do i have to create a custom Layout Manager? or What exactly do i have to do? Please, I am really stuck on this.
This is my adapter code
public class SimpleStringRecyclerViewAdapter : RecyclerView.Adapter
{
private List<Data> mValues;
private Context context;
private const int TYPE_FULL = 0;
private const int TYPE_HALF = 1;
private const int TYPE_QUARTER = 2;
public SimpleStringRecyclerViewAdapter(Context context, List<Data> items)
{
this.context = context;
mValues = items;
}
public override int ItemCount
{
get
{
return mValues.Count();
}
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
if (holder is SimpleViewHolder)
try
{
Data item = mValues.ElementAt(position);
var simpleHolder = holder as SimpleViewHolder;
simpleHolder.mTxtView.Text = Android.Text.Html.FromHtml(item.article.Title).ToString();
simpleHolder.mTxtView2.Text = item.article.Description;
using (var imageView = simpleHolder.mImageView)
{
string url = Android.Text.Html.FromHtml(item.article.UrlToImage).ToString();
//Download and display image
UrlImageViewHelper.SetUrlDrawable(imageView,
url, Resource.Drawable.cheese_1
);
}
// simpleHolder.mprogressbar.Visibility = ViewStates.Gone;
}
catch (Exception e)
{
//Toast.MakeText(this.context, e.ToString(), ToastLength.Long).Show();
}
else
{
try
{
Data item = mValues.ElementAt(position);
var simpleHolder = holder as SimpleViewHolder2;
simpleHolder.mTxtView.Text = Android.Text.Html.FromHtml(item.youTubeItem.Title).ToString();
// simpleHolder.mTxtView2.Text = item.DescriptionShort;
using (var imageView = simpleHolder.mImageView)
{
string url = Android.Text.Html.FromHtml(item.youTubeItem.MaxResThumbnailUrl).ToString();
//Download and display image
UrlImageViewHelper.SetUrlDrawable(imageView,
url, Resource.Drawable.cheese_1
);
}
}
catch (Exception e)
{
//Toast.MakeText(this.context, e.ToString(), ToastLength.Long).Show();
}
}
}
public override int GetItemViewType(int position)
{
if (mValues.ElementAt(position).type == 1)
{
return Resource.Layout.ItemsList;
}
else
{
return Resource.Layout.VideoList;
}
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
if (viewType == Resource.Layout.ItemsList)
{
View view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.ItemsList, parent, false);
view.SetBackgroundColor(Color.White);
SimpleViewHolder holder = new SimpleViewHolder(view);
// holder.mprogressbar = view.FindViewById<ProgressBar>(Resource.Id.progressBar);
// holder.mprogressbar.Visibility = ViewStates.Visible;
//Showing loading progressbar
return holder;
}
else
{
View view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.VideoList, parent, false);
view.SetBackgroundColor(Color.White);
SimpleViewHolder2 holder = new SimpleViewHolder2(view);
return holder;
}
}
}
public class SimpleViewHolder : RecyclerView.ViewHolder
{
public string mBoundString;
public readonly View mView;
public readonly ImageView mImageView;
public readonly TextView mTxtView;
public readonly TextView mTxtView2;
// public ProgressBar mprogressbar;
public SimpleViewHolder(View view) : base(view)
{
mView = view;
mImageView = view.FindViewById<ImageView>(Resource.Id.avatar2);
mTxtView = view.FindViewById<TextView>(Resource.Id.Text11);
mTxtView2 = view.FindViewById<TextView>(Resource.Id.Text12);
// mprogressbar = view.FindViewById<ProgressBar>(Resource.Id.progressBar);
}
public override string ToString()
{
return base.ToString() + " '" + mTxtView.Text;
}
}
public class SimpleViewHolder2 : RecyclerView.ViewHolder
{
public string mBoundString;
public readonly View mView;
public readonly ImageView mImageView;
public readonly TextView mTxtView;
public readonly TextView mTxtView2;
public SimpleViewHolder2(View view) : base(view)
{
mView = view;
mImageView = view.FindViewById<ImageView>(Resource.Id.videoavatar);
mTxtView = view.FindViewById<TextView>(Resource.Id.videoText1);
// mprogressbar = view.FindViewById<ProgressBar>(Resource.Id.progressBar);
}
}
SetUpRecyclerView Method:
dataUse = OfflineDeserializer.OfflineData(content, json2);
recyclerView.SetLayoutManager(new LinearLayoutManager(recyclerView.Context));
recyclerView.SetAdapter(new SimpleStringRecyclerViewAdapter(recyclerView.Context, dataUse));
if (vp.IsShown)
{
vp.Visibility = ViewStates.Invisible;
}
This is what I have presently:

you can use recycler view with multiple view type
here is the link you can refer
Recyclerview with multiple view types
Here is a sample code you can modify it according to your need
public class MyFeedsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
final int
VIDEO = 1,
IMAGE = 2,
AUDIO = 3;
public MyFeedsAdapter(HomeActivity homeActivity, ArrayList<MyFeedsModel> list, MyFeedsFragment myFeedsFragment) {
this.activity = homeActivity;
this.list = list;
this.myFeedsFragment = myFeedsFragment;
metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
switch (viewType) {
case VIDEO:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_myfeeds, parent, false);
return new ViewForVideo(view);
case IMAGE:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_myfeeds, parent, false);
return new ViewForImage(view);
case AUDIO:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_myfeeds, parent, false);
return new ViewForAudio(view);
default:
return null;
}
}
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
if (list.get(position).getFile_type().equals(IntentString.VIDEO)) {
setViewForVideo((ViewForVideo) holder, position);
} else if (list.get(position).getFile_type().equals(IntentString.IMAGE)) {
setViewForImage((ViewForImage) holder, position);
} else if (list.get(position).getFile_type().equals(IntentString.AUDIO)) {
setViewForAudio((ViewForAudio) holder, position);
}
}
#Override
public int getItemCount() {
return list.size();
}
#Override
public int getItemViewType(int position) {
if (list.get(position).getFile_type().equals(IntentString.VIDEO)) {
return VIDEO;
} else if (list.get(position).getFile_type().equals(IntentString.IMAGE)) {
return IMAGE;
} else if (list.get(position).getFile_type().equals(IntentString.AUDIO)) {
return AUDIO;
} else {
return 0;
}
}
public void setViewForVideo(final ViewForVideo holder, final int position) {
}
public void setViewForImage(final ViewForImage holder, final int position) {
}
public void setViewForAudio(final ViewForAudio holder, int position) {
}
public class ViewForVideo extends RecyclerView.ViewHolder {
public ViewForVideo(View itemView) {
super(itemView);
}
}
public class ViewForImage extends RecyclerView.ViewHolder {
public ViewForImage(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
public class ViewForAudio extends RecyclerView.ViewHolder {
public ViewForAudio(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
}

Related

Error null exception in "for" construct xamarin android. Where is incorrect?

This method returns the number of types of Views that will be created by getView method.
public class CustomAdapter : BaseAdapter{
private const int TYPE_ITEM = 0;
private const int TYPE_SEPARATOR = 1;
private List<string> mData;
private TreeSet sectionHeader;
private LayoutInflater mInflater;
public CustomAdapter(Context context, List<string> Data) {
mInflater = (LayoutInflater) context
.GetSystemService(Context.LayoutInflaterService);
this.mData=Data;
}
public void addItem(string item) {
mData.Add(item);
NotifyDataSetChanged();
}
public void addSectionHeaderItem(string item) {
mData.Add(item);
//sectionHeader.Add(mData.Count - 1);
NotifyDataSetChanged();
}
public int getItemViewType(int position) {
return sectionHeader.Contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}
public int getViewTypeCount {
get{ return 2; }
}
public override int Count {
get {return mData.Count;}
}
public override Java.Lang.Object GetItem(int position) {
return mData[position];
}
public override long GetItemId(int position) {
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int rowType = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (rowType) {
case TYPE_ITEM:
convertView = mInflater.Inflate(Resource.Layout.textViewItemsSeparator, parent);
holder.textView = (TextView) convertView.FindViewById(Resource.Id.textviewHeaderItems);
break;
case TYPE_SEPARATOR:
convertView = mInflater.Inflate(Resource.Layout.textViewHeaderItems, parent);
holder.textView = (TextView) convertView.FindViewById(Resource.Id.textviewItemsSeparator);
break;
}
convertView.Tag=holder;
} else {
holder = (ViewHolder)convertView.Tag as ViewHolder;
}
holder.textView.Text=mData[position];
return convertView;
}
public class ViewHolder:Java.Lang.Object {
public TextView textView;
}
}
ListView lst;
string[] items = new string[] { "Alternative Rock","Classical",...........};
List<string> listItems;
private CustomAdapter mAdapter;
public override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
// Create your fragment here
}
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
// return inflater.Inflate(Resource.Layout.YourFragment, container, false);
listItems = new List<string> (items);
return inflater.Inflate (Resource.Layout.GenerFragment, container, false);
}
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
lst = View.FindViewById<ListView> (Resource.Id.lstGenres);
//lst.Adapter = new ArrayAdapter<string>(Activity, Resource.Layout.textViewHeaderItems,Resource.Id.textviewHeaderItems, items);
//lst = View.FindViewById<ListView> (Resource.Id.lst_genre);
//lst.SetAdapter(new ArrayAdapter<String>(this.Activity, Resource.Layout.GenerFragment, items));
//mAdapter=new CustomAdapter();
for (int i = 0; i < listItems.Count(); i++) {
mAdapter.addItem (listItems[i]);
if (i == 0) {
mAdapter.addSectionHeaderItem ("Music");
} else if(i==13) {
mAdapter.addSectionHeaderItem ("Audio");
}
}
lst.Adapter = new CustomAdapter (Activity, listItems);
I spent much time for looking for errors but I have no idea why It was null. although It got a data from list
mAdapter.addItem (listItems[i]); -> null exception when I debug on device. Where is incorrect?
in OnActivityCreated you are referencing listItems
for (int i = 0; i < listItems.Count(); i++) {
however, listItems is null. You initialize it in OnCreateView, which has not been executed yet. You need to be sure that listItems is initialized before you attempt to reference it.
Additionally, you are attempting to add items to mAdapter, but it's never been initialized (as far as I can see)
you declare it here, but it will be NULL until you initalize it
private CustomAdapter mAdapter;
here is the initialization, which is commented out
//mAdapter=new CustomAdapter();
when you attempt to reference it here, it is still null, and will throw a Null Reference Exception
mAdapter.addItem (listItems[i]);

cannot convert CustomAdapter expression to type System.Collections.Generic.List<string> on xamarin android

string[] items = new string[] { "Alternative Rock","Classical", "Country"}
for (int i = 0; i <= items.Count(); i++) {
mAdapter.addItem (items [i].ToString ());
if (i == 0) {
mAdapter.addSectionHeaderItem ("Music");
} else if(i==13) {
mAdapter.addSectionHeaderItem ("Audio");
}
}
lst.Adapter = new CustomAdapter (Activity, mAdapter);
public class CustomAdapter : BaseAdapter{
private const int TYPE_ITEM = 0;
private const int TYPE_SEPARATOR = 1;
private List<string> mData;
private TreeSet sectionHeader;
private LayoutInflater mInflater;
public CustomAdapter(Context context, List<string> mData) {
mInflater = (LayoutInflater) context
.GetSystemService(Context.LayoutInflaterService);
this.mData=mData;
}
public void addItem( string item) {
mData.Add(item);
NotifyDataSetChanged();
}
public void addSectionHeaderItem(string item) {
mData.Add(item);
sectionHeader.Add(mData.Count - 1);
NotifyDataSetChanged();
}
public int getItemViewType(int position) {
return sectionHeader.Contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}
public int getViewTypeCount {
get{ return 2; }
}
public override int Count {
get {return mData.Count;}
}
public override Java.Lang.Object GetItem(int position) {
return null;
}
public override long GetItemId(int position) {
return position;
}
public View GetView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int rowType = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (rowType) {
case TYPE_ITEM:
convertView = mInflater.Inflate(Resource.Layout.textViewItemsSeparator, parent);
holder.textView = (TextView) convertView.FindViewById(Resource.Id.textviewHeaderItems);
break;
case TYPE_SEPARATOR:
convertView = mInflater.Inflate(Resource.Layout.textViewHeaderItems, parent);
holder.textView = (TextView) convertView.FindViewById(Resource.Id.textviewItemsSeparator);
break;
}
convertView.Tag=holder;
} else {
holder = (ViewHolder)convertView.Tag as ViewHolder;
}
holder.textView.Text=mData[position];
return convertView;
}
public class ViewHolder:Java.Lang.Object {
public TextView textView;
}
cannot convert CustomAdapter expression to type System.Collections.Generic.List on xamarin android at
CustomAdapter : BaseAdapter and new CustomAdapter (Activity,
mAdapter);
Blockquote
In this example we will show how to create a ListView with section header. This involves following steps
Update my post.
the signature for your CustomAdapter constructor specifies two arguments, a context and a List<string>
public CustomAdapter(Context context, List<String> mData) {
however, when you create it, you are passing mAdapter for the 2nd argument instead of a List<string>.
lst.Adapter = new CustomAdapter (Activity, mAdapter);

How to create header xamarin listview?

lst.Adapter=new CustomAdapter(Android.App.Application.Context,items);
public class CustomAdapter : BaseAdapter
{
private const int TYPE_ITEM = 0;
private const int TYPE_SEPARATOR = 1;
string[] mnData;
//private TreeSet sectionHeader;
LayoutInflater mInflater;
TreeSet sectionHeader;
public CustomAdapter(Context context, string[] Data) {
mInflater = LayoutInflater.FromContext (context);
mnData=Data;
}
public override int GetItemViewType (int position)
{
return sectionHeader.Contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}
public override int ViewTypeCount
{
get { return 2; }
}
public override int Count {
get {return mnData.Length;}
}
public override Java.Lang.Object GetItem(int position) {
return mnData[position];
}
public override long GetItemId(int position) {
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
//var data = mData [position];
var item=mnData[position];
int row = GetItemViewType (position);
if (convertView == null) {
holder = new ViewHolder ();
switch (row) {
case TYPE_ITEM:
convertView = mInflater.Inflate (Resource.Layout.textGenreItems, parent, false);
holder.textView = (TextView)convertView.FindViewById (Resource.Id.textTitleGenre);
break;
case TYPE_SEPARATOR:
convertView = mInflater.Inflate (Resource.Layout.textGenreHeaderItems, parent, false);
holder.textView = (TextView)convertView.FindViewById (Resource.Id.textHeaderGenre);
break;
}
convertView.Tag = holder;
} else {
holder = (ViewHolder)convertView.Tag as ViewHolder;
}
return convertView;
}
}
public class ViewHolder:Java.Lang.Object {
public TextView textView{ get; set; }
//public TextView textViewSeparator{ get; set; }
I want to create a listview as following picture. How to do that?
Here's how I do it, the keys are getItemViewType and getViewTypeCount in the Adapter class. getViewTypeCount returns how many types of items we have in the list, in this case we have a header item and an event item, so two. getItemViewType should return what type of View we have at the input position.
Android will then take care of passing you the right type of View in convertView automatically.

Adapter showing the wrong images while using Fresco library

i have used fresco library to load images in the adapter. but the images are not set correctly as i expected. Here is my code. please help me. thanks in advance.
public class HomeListingAdapter_recyler1 extends RecyclerView.Adapter {
private Context context;
private ArrayList propertyItemList;
private ImageLoader mImageLoader;
public HomeListingAdapter_recyler1(HomeListingActivity_recycler propertyViews, ArrayList propertyItemList) {
Fresco.initialize(propertyViews);
this.propertyItemList = propertyItemList;
this.context = propertyViews;
}
#Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.property_item_layout,parent,false);
CustomViewHolder viewHolder = new CustomViewHolder(itemLayoutView);
return viewHolder;
}
#Override
public void onBindViewHolder(final CustomViewHolder holder, final int position) {
mImageLoader = VolleySingletonPattern.getInstance(context).getImageLoader();
holder.txtPropertyName.setText(propertyItemList.get(position).ville);
holder.txtPropertyType.setText(propertyItemList.get(position).bienName);
if(propertyItemList.get(position).pieces.equalsIgnoreCase("0")){
holder.txtPropertySurfaceArea.setText(propertyItemList.get(position).surface+" "+context.getString(R.string.meter_square));
}else{ holder.txtPropertySurfaceArea.setText(propertyItemList.get(position).surface+" "+context.getString(R.string.meter_square)+" - "+ propertyItemList.get(position).pieces+" "+context.getResources().getString(R.string.pieces));
}
holder.txtPropertyPrice.setText(propertyItemList.get(position).montantLoyer);
Uri imageUri;
try {
if(!TextUtils.isNullOrEmpty(propertyItemList.get(position).photo)) {
imageUri = Uri.parse(propertyItemList.get(position).photo);
holder.imgPropertyImage.setVisibility(View.VISIBLE);
holder.imgPropertyImage.setImageURI(imageUri);
}
} catch (Exception e) {
}
}
#Override
public int getItemCount() {
return propertyItemList.size();
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
SimpleDraweeView imgPropertyImage;
public TextView txtPropertyName , txtPropertyType , txtPropertySurfaceArea ,txtPropertyPrice;
public CustomViewHolder(View itemView) {
super(itemView);
imgPropertyImage = (SimpleDraweeView) itemView.findViewById(R.id.image_property);
txtPropertyName = (TextView) itemView.findViewById(R.id.txt_property_name);
txtPropertyType = (TextView) itemView.findViewById(R.id.txt_property_type);
txtPropertySurfaceArea = (TextView) itemView.findViewById(R.id.txt_property_surface_piece);
txtPropertyPrice = (TextView) itemView.findViewById(R.id.txt_property_price);
}
}
}
Your imgPropertyImage should be a SimpleDraweeView, not an ImageView.

Memory leak with view pager and fragment

In this part of my application there is a ViewPager contents in a fragment,
when i replace the fragment contains the viewpager android doesn't clear the memory.
How can I clear the memory?
this is the adapter for the listview:
public class LineeAdapter extends ArrayAdapter<Linea> {
private final List<Linea> list;
private final Activity context;
private final int layout;
public LineeAdapter(Activity context,int layout, List<Linea> list) {
super(context, layout, list);
this.context = context;
this.list = list;
this.layout=layout;
}
static class ViewHolder {
protected TextView text;
protected TextView text1;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(layout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.cod_linea);
viewHolder.text1 = (TextView) view.findViewById(R.id.descrizione_linea);
view.setTag(viewHolder);
} else {
view = convertView;
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getCod_Linea());
holder.text1.setText(list.get(position).getDesc_Linea());
return view;
}
this is the fragmet contain in the view pager
public class TempiAtt_Linee extends Fragment
{
View view;
ListView lw;
int dati;
LineeAdapter adapter;
List<Linea> linee ;
static TempiAtt_Linee newInstance(int num)
{
TempiAtt_Linee f = new TempiAtt_Linee();
return f;
}
#Override
public void onDestroyView()
{
super.onDestroyView();
getView().destroyDrawingCache();
linee.clear();
adapter.notifyDataSetChanged();
adapter.clear();
view = null;
lw = null;
linee = null;
System.gc();
}
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
linee= new ArrayList<Linea>();
for (int i = 0; i < Main.GeneralObject.getLinee().size(); i++)
{
this.linee.add(Main.GeneralObject.getLinee().get(i));
}
lw = (ListView) getView().findViewById(R.id.list_view);
adapter = new LineeAdapter(getActivity(), R.layout.row_linea, linee);
lw.setAdapter(adapter);
lw.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3)
{
ArrayList<Percorso> tratte = linee.get(position).getPercorsi();
Fragment fragment = new TempiAtt_Percorsi();
FragmentManager fragmentManager = getActivity()
.getSupportFragmentManager();
Bundle temp = new Bundle();
temp.putString("linea", linee.get(position).getCod_Linea()
.replace(" ", "_"));
temp.putSerializable("tratte",
SerializerClass.serializeObject(tratte));
fragment.setArguments(temp);
fragmentManager.beginTransaction().addToBackStack(null)
.replace(R.id.content_frame, fragment).commit();
}
});
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
view = inflater.inflate(R.layout.generic_listview, container, false);
return view;
}
}
and this is the fragment of the viewpager:
public class TempiAtt extends Fragment {
// list contains fragments to instantiate in the viewpager
List<Fragment> fragments = null;
int NUM = 3;
List<String> fragmentTitles = null;
// page adapter between fragment list and view pager
private MyAdapter mPagerAdapter = null;
// view pager
private ViewPager mViewPager;
private Handler handler;
View view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.main_prova, container, false);
return view;
}
public void clear() {
if (null != mViewPager) {
mViewPager.removeAllViews();
}
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViewPager = (ViewPager) getView().findViewById(R.id.pager);
fragments = new Vector<Fragment>();
setRetainInstance(true);
fragmentTitles = new Vector<String>();
Bundle scheda = new Bundle();
scheda.putInt("scheda", 0);
// creating fragments and adding to list
fragments.add(Fragment.instantiate(getActivity(),
TempiAtt_Linee.class.getName(), scheda));
fragmentTitles.add(getActivity().getResources().getString(
R.string.urbana_como));
Bundle scheda1 = new Bundle();
scheda1.putInt("scheda", 1);
fragments.add(Fragment.instantiate(getActivity(),
TempiAtt_Linee.class.getName(), scheda1));
fragmentTitles.add(getActivity().getResources().getString(
R.string.extraurbana));
Bundle scheda2 = new Bundle();
scheda2.putInt("scheda", 2);
fragments.add(Fragment.instantiate(getActivity(),
TempiAtt_Linee.class.getName(), scheda2));
fragmentTitles.add(getActivity().getResources().getString(
R.string.urbana_cantu));
View pagerStrip = super.getView().findViewById(R.id.pagerTabStrip);
if (pagerStrip instanceof PagerTabStrip) {
PagerTabStrip pagerTabStrip = (PagerTabStrip) pagerStrip;
pagerTabStrip.setDrawFullUnderline(true);
pagerTabStrip.setTabIndicatorColorResource(R.color.bianco);
} else if (pagerStrip instanceof PagerTitleStrip) {
PagerTitleStrip pagerTitleStrip = (PagerTitleStrip) pagerStrip;
pagerTitleStrip.setTextColor(getResources().getColor(
android.R.color.white));
}
/*
* this.mPagerAdapter = new PagerAdapter(getChildFragmentManager(),
* fragments, fragmentTitles);
* mViewPager.setAdapter(this.mPagerAdapter);
* mViewPager.setCurrentItem(0);
*/
mPagerAdapter = new MyAdapter(getChildFragmentManager());
handler = new Handler();
handler.post(new Runnable() {
#Override
public void run() {
mViewPager.setAdapter(mPagerAdapter);
}
});
mViewPager.setOffscreenPageLimit(2);
}
#Override
public void onDestroyView() {
super.onDestroyView();
onDestroy();
deleteCard();
clear();
view = null;
System.gc();
}
public void deleteCard() {
// Reduce the card counter by one
NUM -= 3;
for (int i = 0; i < fragments.size(); i++) {
fragments.remove(i);
Log.e("SONO IO", fragments.size() + "");
}
mPagerAdapter.notifyDataSetChanged();
}
private class MyAdapter extends FragmentPagerAdapter {
private SparseArray<WeakReference<TempiAtt_Linee>> mPageReferenceMap = new SparseArray<WeakReference<TempiAtt_Linee>>();;
public MyAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int index) {
return getFragment(index);
}
#Override
public int getCount() {
return NUM;
}
public int getItemPosition(Object object) {
return POSITION_NONE;
}
public TempiAtt_Linee getFragment(int key) {
WeakReference<TempiAtt_Linee> weakReference = mPageReferenceMap
.get(key);
if (null != weakReference) {
return (TempiAtt_Linee) weakReference.get();
} else {
return null;
}
}
public Object instantiateItem(ViewGroup container, int position) {
TempiAtt_Linee tempiAttLinee = TempiAtt_Linee.newInstance(position);
mPageReferenceMap.put(Integer.valueOf(position),
new WeakReference<TempiAtt_Linee>(tempiAttLinee));
return super.instantiateItem(container, position);
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
mPageReferenceMap.remove(Integer.valueOf(position));
}
}
}

Resources