android - Grow heap (frag case) on ListView Fragment using custom ParseQueryAdapter on fast scrolling -



android - Grow heap (frag case) on ListView Fragment using custom ParseQueryAdapter on fast scrolling -

i using parse.com android sdk. within tabsactivity.java, have searchfragment extends listfragment in order populate listview custom parsequeryadapter. within custom adapter declare custom list row layout called search_list_item.xml. layout contains parseimageview.

my problem when fast scroll downwards list logcat gets total of

i/dalvikvm-heap﹕ grow heap (frag case) ...mb byte allocation

and the listview returns initial position(that means gets first item). if on other hand scroll list can @ end of items without error. how prepare this??

additionally, if utilize default parsequeryadapter without customizing rows search_list_item.xml don't have such problem.

below post code think useful:

the code of search_list_item.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <com.parse.parseimageview android:id="@+id/profileimage" android:layout_width="match_parent" android:layout_height="wrap_content" /> </relativelayout>

the code of tabsactivity.java

public class tabsactivity extends activity implements searchfragment.onfragmentinteractionlistener, actionbar.tablistener { /** * {@link android.support.v4.view.pageradapter} provide * fragments each of sections. utilize * {@link fragmentpageradapter} derivative, maintain every * loaded fragment in memory. if becomes memory intensive, * may best switch * {@link android.support.v13.app.fragmentstatepageradapter}. */ sectionspageradapter msectionspageradapter; /** * {@link viewpager} host section contents. */ viewpager mviewpager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tabs); // set action bar. final actionbar actionbar = getactionbar(); actionbar.setlogo(r.drawable.logo_white); actionbar.setdisplayshowtitleenabled(false); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); // create adapter homecoming fragment each of 3 // primary sections of activity. msectionspageradapter = new sectionspageradapter(getfragmentmanager()); // set viewpager sections adapter. mviewpager = (viewpager) findviewbyid(r.id.tabs_pager); mviewpager.setadapter(msectionspageradapter); // when swiping between different sections, select corresponding // tab. can utilize actionbar.tab#select() if have // reference tab. mviewpager.setonpagechangelistener(new viewpager.simpleonpagechangelistener() { @override public void onpageselected(int position) { actionbar.setselectednavigationitem(position); } }); // each of sections in app, add together tab action bar. actionbar.addtab( actionbar.newtab() .settext("search") .settablistener(this)); actionbar.addtab( actionbar.newtab() .settext("secind") .settablistener(this)); actionbar.addtab( actionbar.newtab() .settext("third") .settablistener(this) ); actionbar.addtab( actionbar.newtab() .settext("fourth") .settablistener(this)); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.tabs, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { } homecoming super.onoptionsitemselected(item); } @override public void ontabselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { // when given tab selected, switch corresponding page in // viewpager. mviewpager.setcurrentitem(tab.getposition()); } @override public void ontabunselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { } @override public void ontabreselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { } /** * {@link fragmentpageradapter} returns fragment corresponding * 1 of sections/tabs/wizard1. */ public class sectionspageradapter extends fragmentpageradapter { public sectionspageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int index) { switch (index) { case 0: // search fragment activity homecoming new searchfragment(); case 1: // flirts fragment activity homecoming new secondfragment(); case 2: // explore fragment activity homecoming new thirdfragment(); case 3: //profile fragment activity homecoming new fourthfragment(); } homecoming null; } @override public int getcount() { // show 4 total wizard1. homecoming 4; } } public void onfragmentinteraction(string id) { // user selected headline of article headlinesfragment // here display article } }

the code of searchfragment.java

public class searchfragment extends listfragment { private onfragmentinteractionlistener mlistener; private customdogadapter mainadapter; /** * mandatory empty constructor fragment manager instantiate * fragment (e.g. upon screen orientation changes). */ public searchfragment() { } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mainadapter = new customadapter(this.getactivity()); // set listactivity's adapter pqa mainadapter.setautoload(false); mainadapter.loadobjects(); setlistadapter(mainadapter); } @override public void onattach(activity activity) { super.onattach(activity); seek { mlistener = (onfragmentinteractionlistener) activity; } grab (classcastexception e) { throw new classcastexception(activity.tostring() + " must implement onfragmentinteractionlistener"); } } @override public void ondetach() { super.ondetach(); mlistener = null; } @override public void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); if (null != mlistener) { // notify active callbacks interface (the activity, if // fragment attached one) item has been selected. } } /** * interface must implemented activities contain * fragment allow interaction in fragment communicated * activity , potentially other fragments contained in * activity. * <p> * see android training lesson <a href= * "http://developer.android.com/training/basics/fragments/communicating.html" * >communicating other fragments</a> more information. */ public interface onfragmentinteractionlistener { // todo: update argument type , name public void onfragmentinteraction(string id); } }

the code of customadapter.java

public class customadapter extends parsequeryadapter<parseobject> { public customadapter(context context) { // utilize queryfactory build pqa show // todos marked high-pri super(context, new parsequeryadapter.queryfactory<parseobject>() { public parsequery create() { parsequery query = new parsequery("photo"); query.whereequalto("imagename", "profileimage"); // query.setcachepolicy(parsequery.cachepolicy.cache_else_network); homecoming query; } }); } // customize layout overriding getitemview @override public view getitemview(parseobject object, view v, viewgroup parent) { if (v == null) { v = view.inflate(getcontext(), r.layout.search_list_item, null); } super.getitemview(object, v, parent); // add together , download image parseimageview image = (parseimageview) v.findviewbyid(r.id.profileimage); parsefile photofile = object.getparsefile("imagefile"); if (photofile != null) { image.setparsefile(photofile); image.loadinbackground(); // (new getdatacallback() { // @override // public void done(byte[] data, parseexception e) { // // nil // } // }); } // // add together title view // textview titletextview = (textview) v.findviewbyid(r.id.text1); // titletextview.settext(object.getstring("title")); // // // add together reminder of how long item has been outstanding // textview timestampview = (textview) v.findviewbyid(r.id.timestamp); // timestampview.settext(object.getcreatedat().tostring()); homecoming v; } }

i have studied lot of times , followed these documentations parse.com

1) ui-parsequeryadapter

2) mealspotting

thank much time , sorry long post, tried explanatory possible.

after more general searching abot list views , performance stepped across blog post has interesting lastly paragraph says:

never set height of listview wrap_content. if have info locally available, might not seem bad, becomes particularly troublesome when don’t. if utilize wrap_content on listview, happens: first getview phone call done, convertview null, , position 0 loaded. now, position 1 loaded, passed view generated position 0 convertview. position 2 loaded same view, , on. done lay out listview since has figure out how tall should , didn’t explicitly tell it. 1 time has run through of positions, view passed position 0 yet getview call, , position 1 , on loaded getview , no convertview. you’re going end seeing getview called 2 or 3 times have expected. not suck performance, can confusing issues.

source: read lastly paragraph

i don't understand new development, after reading decided alter layout height , width predefined dp values , set android:scaletype="centercrop". solved grow heap issue , scrolling became smooth.

i hope finds helpful did, , if can explain more technically interested in reading it. give thanks much in advance!

android parse.com android-listfragment custom-adapter android-parsequeryadapter

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -