i'm using universal image loader to populate thumbnails into gridview from assets gallary but images are loading slowly during scrolling up or down so i think because images are being loaded with it's current resolution so how i can change the resolution of the images for example i used to use createScaledBitmap to scale down the bitmap
Here is my code :
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private List<String> mList;
private int mheight;
private int mwidth;
private InputStream is;
private HomePage homePage;
private ImageLoader imageLoader;
public ImageAdapter(Context context, List<String> list, int height, int width) {
mContext = context;
mList = list;
mheight = height;
mwidth = width;
ImageLoader imageLoader = ImageLoader.getInstance();
this.imageLoader = imageLoader;
}
#Override
public int getCount() {
return mList.size();
}
#Override
public Object getItem(int position) {
return mList.get(position).toString();
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
} else {
imageView = (ImageView) convertView;
}
File cacheDir = new File(Environment.getExternalStorageDirectory(), "UniversalImageLoader/Cache");
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)
.threadPoolSize(5)
.memoryCacheExtraOptions(mwidth/3, mwidth/3)
.threadPriority(Thread.MIN_PRIORITY )
.memoryCache(new UsingFreqLimitedMemoryCache(5000000)) // You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.build();
imageLoader.init(config);
//
//
//display options
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.loading)
.showImageForEmptyUri(R.drawable.loading)
.cacheInMemory()
.cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.EXACTLY)
.build();
// // Create configuration for ImageLoader
String imString = mList.get(position);
String imageUria = "assets://"+imString;
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(mwidth/3, mwidth/3));
imageLoader.displayImage(imageUria, imageView ,options );
return imageView ;
}
}
Related
Im setting my imageview using picasso, because I just have url for my image. I have using listview to display. In custom adapter I'm setting imageview using picasso. But image is not displayed in listview. I doesn't know where the problem is... Anybody help out to solve this.... Thanks in advance
public class GetReportAdapter extends ArrayAdapter<NewsReport> {
private ArrayList<NewsReport> newsReports;
public GetReportAdapter(Context context, ArrayList<NewsReport> newsReportArrayList)
{
super(context, 0,newsReportArrayList);
this.newsReports=newsReportArrayList;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
NewsReport currentReport=getItem(position);
TextView titleTextView=(TextView) listItemView.findViewById(R.id.title_text_view);
titleTextView.setText(currentReport.getTitle());
TextView channelTextView=(TextView) listItemView.findViewById(R.id.news_channel_text_view);
channelTextView.setText(currentReport.getChannel());
ImageView pictureImageView=(ImageView) listItemView.findViewById(R.id.news_pic_image_view);
Log.e("image urlString",currentReport.getImage());
Picasso.with(listItemView.getContext()).load(currentReport.getImage()).into(pictureImageView);
return listItemView;
}
}
Here Im setting listview
public class MainActivity extends AppCompatActivity {
static final Uri CONTENT_URL = Uri.parse("content://com.example.newsreport/newsfeed");
ContentResolver resolver;
ArrayList<NewsReport> newsReportArrayList = new ArrayList<NewsReport>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
resolver = getContentResolver();
Log.e("resolver", "" + resolver);
getNewsFeed();
setAdapter();
}
public void getNewsFeed() {
String id = null;
String title = null;
String content = null;
String channel = null;
String image = null;
String[] projection = new String[]{BaseColumns._ID, "title", "channel", "image", "content"};
Cursor cursor = getContentResolver().query(CONTENT_URL, projection, null, null, null);
String newsFeed = "";
if (cursor.moveToNext()) {
do {
id = cursor.getString(cursor.getColumnIndex(BaseColumns._ID));
title = cursor.getString(cursor.getColumnIndex("title"));
Log.e("title", title);
content = cursor.getString(cursor.getColumnIndex("content"));
Log.e("content", "" + content);
channel = cursor.getString(cursor.getColumnIndex("channel"));
Log.e("channel", "" + channel);
image = cursor.getString(cursor.getColumnIndex("image"));
Log.e("image", "" + image);
newsReportArrayList.add( new NewsReport(channel,title,image));
} while (cursor.moveToNext());
}
}
public void setAdapter()
{
ListView list=(ListView) findViewById(R.id.list);
GetReportAdapter adapter= new GetReportAdapter(this,newsReportArrayList);
list.setAdapter(adapter);
}
}
I have created a CollapsablePane which shows an EffectImageView as collapsableContent, and a Node as mainContent. The EffectImageView consists of two layered ImageViews, the bottom one having an BoxBlur effect applied on it.
When there is a ScrollEvent on the mainContent the collapsableContent will be animated accordingly by setTranslateY.
With a BoxBlur effect applied, the translation of the lower part of the collapsableContent is very unsmooth, while it is absolutely smooth without the effect.
Is there a possibility to improve the transition performance?
public class EffectImageView extends Pane {
private ImageView img;
private ImageView imgEffect;
private Rectangle clipTop;
private Rectangle clipBottom;
private DoubleProperty imageEffectHeight = new SimpleDoubleProperty();
private double effectOffset;
public EffectImageView() {
img = createCachedImageView();
imgEffect = createCachedImageView();
imgEffect.imageProperty().bind(img.imageProperty());
imgEffect.fitWidthProperty().bind(img.fitWidthProperty());
imgEffect.fitHeightProperty().bind(img.fitHeightProperty());
clipTop = new Rectangle();
clipTop.widthProperty().bind(img.fitWidthProperty());
clipTop.heightProperty().bind(img.fitHeightProperty().subtract(imageEffectHeight).subtract(translateYProperty()));
clipBottom = new Rectangle();
clipBottom.widthProperty().bind(img.fitWidthProperty());
clipBottom.heightProperty().bind(imageEffectHeight);
clipBottom.translateYProperty().bind(heightProperty().subtract(imageEffectHeight).subtract(translateYProperty()));
img.setClip(clipTop);
imgEffect.setClip(clipBottom);
getChildren().addAll(img, imgEffect);
}
private ImageView createCachedImageView() {
ImageView img = new ImageView();
img.setCache(true);
img.setCacheHint(CacheHint.SPEED);
return img;
}
public final ObjectProperty<Image> imageProperty() {
return img.imageProperty();
}
public final Image getImage() {
return img.getImage();
}
public final void setImage(Image image) {
img.setImage(image);
}
public void setImageEffect(Effect effect) {
imgEffect.setEffect(effect);
}
public final DoubleProperty imageEffectHeightProperty() {
return imageEffectHeight;
}
public void setEffectOffset(double offset) {
effectOffset = offset;
}
#Override
protected void layoutChildren() {
double w = getWidth();
double h = getHeight();
img.relocate(-effectOffset, 0);
imgEffect.relocate(-effectOffset, 0);
img.setFitWidth(w + effectOffset * 2);
img.setFitHeight(h);
}
}
I am trying to build a Grid View inside Expandable list view. The problem i am facing is that the the columns in gridview are repeating no matter the number of columns i specify in xml. please find below the code and screen shot. That is there are two child view A and B. Instead of each coming in a single row. A is coming completely on 1st row no matter the number of columns and B is coming on the complete second rows.
ExpandableListAdapter
public class ExpandListAdapter extends BaseExpandableListAdapter {
private Activity activity;
private Context context;
private ArrayList<GroupModel> mMainDatabase;
private LayoutInflater inflater;
private ArrayList<String> parentItems, child, child1, child2;
private CustomGrid adapter;
private GridView grid;
ViewHolder viewHolder;
private static final String LOG_TAG = ExpandListAdapter.class.getSimpleName();
public ExpandListAdapter(ArrayList<GroupModel> mMainDatabase) {
this.mMainDatabase = mMainDatabase;
}
public void setInflater(LayoutInflater inflater, Activity activity) {
this.inflater = inflater;
this.activity = activity;
}
#Override
public int getGroupCount() {
return mMainDatabase.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return mMainDatabase.get(groupPosition).getItemModels().size();
}
#Override
public Object getGroup(int groupPosition) {
return mMainDatabase.get(groupPosition);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return child.get(childPosition);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView;
// if (convertView == null) {
// inflate the adapter_side
LayoutInflater vi = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.fragment_list_item, null);
// well set up the ViewHolder
viewHolder = new ViewHolder();
viewHolder.title = (TextView) v.findViewById(R.id.item_title);
viewHolder.image = (ImageView) v.findViewById(R.id.item_image);
viewHolder.image.setId(groupPosition);
if (mMainDatabase.get(groupPosition).getGroupImage() != null &&
!mMainDatabase.get(groupPosition).getGroupImage().equals(""))
Utilities.displayImage(activity.getApplicationContext(), mMainDatabase.get(groupPosition).getGroupImage(), viewHolder.image);
else
Picasso.with(activity).load("http://www.google.com")
.into(viewHolder.image);
viewHolder.title
.setText(mMainDatabase.get(groupPosition).getGroupName());
viewHolder.arrowExpand = (ImageView) v.findViewById(R.id.arrowExpand);
if (isExpanded)
viewHolder.arrowExpand.setImageResource(R.drawable.dropdown2);
else
viewHolder.arrowExpand.setImageResource(R.drawable.dropdown);
return v;
}
#Override
public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
// LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.grid_view, null);
}
grid = (GridView) convertView.findViewById(R.id.grid);
adapter = new CustomGrid(activity, groupPosition, childPosition,activity, mMainDatabase);
grid.setAdapter(adapter);
grid.setTag(childPosition);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(activity, FoodDetailActivity.class);
intent.putExtra("item", mMainDatabase.get(groupPosition).getItemModels().
get(Integer.parseInt(view.getTag().toString())));
intent.putExtra("grpId", mMainDatabase.get(groupPosition).get_id());
intent.putExtra("atBottom", true);
activity.startActivity(intent);
}
});
return convertView;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
#Override
public void onGroupExpanded(int groupPosition) {
super.onGroupExpanded(groupPosition);
}
#SuppressLint("NewApi")
#Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
// ImageView img_selection = (ImageView) groupPosition
// .findViewById(R.id.arrowExpand);
}
static class ViewHolder {
TextView title;
TextView number;
TextView numbertxt;
ImageView image, arrowExpand;
Bitmap b;
int position;
}
}
Custom Grid Adapter
public class CustomGrid extends BaseAdapter {
private Context mContext;
private ArrayList<String> mItemName = null;
private ArrayList<String> mItemImage = null;
private int groupPosition, childPosition;
Activity activity;
ArrayList<GroupModel> mMainDatabase;
LayoutInflater inflater;
public CustomGrid(Context c,
int groupPosition, int childPosition, Activity activity, ArrayList<GroupModel> mMainDatabase) {
mContext = c;
this.groupPosition = groupPosition;
this.childPosition = childPosition;
this.activity = activity;
this.mMainDatabase = mMainDatabase;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return mMainDatabase.get(groupPosition).getItemModels().size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mContext);
grid = inflater.inflate(R.layout.grid_single, null);
TextView textView = (TextView) grid.findViewById(R.id.grid_text);
ImageView imageView = (ImageView)grid.findViewById(R.id.grid_image);
textView.setText(mMainDatabase.get(groupPosition).getItemModels()
.get(childPosition).getItemName());
Log.d("CUSTOMGRID", "child name is " + mMainDatabase.get(groupPosition).getItemModels()
.get(childPosition).getItemName() + " child position is " + childPosition);
if (mMainDatabase.get(groupPosition).getItemModels().get(childPosition).getItemImage() != null &&
!mMainDatabase.get(groupPosition).getItemModels().get(childPosition).getItemImage()
.equals(""))
Picasso.with(activity)
.load(mMainDatabase.get(groupPosition).getItemModels()
.get(childPosition).getItemImage())
.placeholder(R.drawable.place).into(imageView);
else
Picasso.with(activity).load("http://www.google.com")
.placeholder(R.drawable.place).into(imageView);
} else {
grid = (View) convertView;
}
return grid;
}
}
I've been searching everywhere for the solution, but it has come to a dead end.
Please help!
I record and save the video as the follow:
File DirectoryFile = new File(VideoPath);
recorder.setOutputFile(DirectoryFile.getAbsolutePath());
I load all the videos and set the ListView adapter from the userPath as follow:
private File[] getNewImageFilesWithFilters() {
File directory = new File(UserSavedDirectoryPATH);
return directory.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase(Locale.getDefault()).endsWith(".mp4")
|| name.toLowerCase(Locale.getDefault()).endsWith(".mkv");
}
});
}
public void LoadListView() {
for (File file : listFile){
mVideoListViewObject = new VideoListViewObject();
mVideoListViewObject.setName(file.getName());
mVideoListViewObject.setVideoUrl(file.getAbsolutePath());
VideoListViewObject_List.add(mVideoListViewObject);
}
mVideoListViewAdapter = new VideoListAdapter(this, VideoListViewObject_List);
mListView.setAdapter(mVideoListViewAdapter);
}
The ListView Adapter:
public class VideoListAdapter extends BaseAdapter {
private List<VideoListViewObject> VideoObjectList;
private Context mContext;
public VideoListAdapter(Context context, List<VideoListViewObject> newList){
this.mContext = context;
this.VideoObjectList = newList;
}
#Override
public int getCount() {
return VideoObjectList.size();
}
#Override
public VideoListViewObject getItem(int position) {
return VideoObjectList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.listview_layout, parent, false);
viewHolder.imageView = (ImageView)convertView.findViewById(R.id.ListViewImage);
viewHolder.layout = (RelativeLayout)convertView.findViewById(R.id.ListViewLayout);
convertView.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder)convertView.getTag();
}
Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(VideoObjectList.get(position).getVideoUrl(),Thumbnails.MICRO_KIND);
viewHolder.imageView.setImageBitmap(bmThumbnail);
The problem is the list is slow to load, especially when there are a lot of videos.
This causes my VideoaAtivity to start very slow.
I love Piscasso and Universal Image Loader, but they only support images.
Does anyone know a better solution or a library that would help with the performance?
Thank you very much.
I just modified my own application to do similar logic to pre-create the thumbnails which made the list scroll very fast at the start, Add the thumbnail bitmap to the videoListViewObject and create the thumbnail
when loading the video list. this way you do not have to create it every time getView is called in your adapter.
public class VideoListViewObject{
private Bitmap bitmap = null;
............................
public void setBitmap(Bitmap bitmap)
{
this.bitmap = bitmap;
}
public Bitmap getBitmap()
{
return this.bitmap;
}
}
public void LoadListView() {
for (File file : listFile){
mVideoListViewObject = new VideoListViewObject();
mVideoListViewObject.setName(file.getName());
mVideoListViewObject.setVideoUrl(file.getAbsolutePath());
Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(VideoObjectList.get(position).getVideoUrl(),Thumbnails.MICRO_KIND);
mVideoListViewObject.setBitmap(bmThumbnail);
VideoListViewObject_List.add(mVideoListViewObject);
}
mVideoListViewAdapter = new VideoListAdapter(this, VideoListViewObject_List);
mListView.setAdapter(mVideoListViewAdapter);
}
then change your BaseAdapter code to only create the thumbnail if it is null,
public class VideoListAdapter extends BaseAdapter {
private List<VideoListViewObject> VideoObjectList;
private Context mContext;
public VideoListAdapter(Context context, List<VideoListViewObject> newList){
this.mContext = context;
this.VideoObjectList = newList;
}
#Override
public int getCount() {
return VideoObjectList.size();
}
#Override
public VideoListViewObject getItem(int position) {
return VideoObjectList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.listview_layout, parent, false);
viewHolder.imageView = (ImageView)convertView.findViewById(R.id.ListViewImage);
viewHolder.layout = (RelativeLayout)convertView.findViewById(R.id.ListViewLayout);
convertView.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder)convertView.getTag();
}
VideoListViewObject mVideoListViewObject = getItem(position);
Bitmap bmThumbnail = mVideoListViewObject.getBitmap();
if(bmThumbnail==null)
{
bmThumbnail = ThumbnailUtils.createVideoThumbnail(VideoObjectList.get(position).getVideoUrl(),Thumbnails.MICRO_KIND);
}
viewHolder.imageView.setImageBitmap(bmThumbnail);
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));
}
}
}