loops - how to optimize many dynamic views in android? -
i programming calendar shows 365 days of year of 4 years (more 1400 view) every day contains linearlayout holds text , background color of date.
in logcat receive memory leak , message activity doing works. generate linearlayouts programmatically id loop. how can optimize memory? using view inflater? putting views in hard coded xml? getting instance of object , modify it? or what?
my current code:
linearlayout item=null; while (year<2020){ month=0; while (month<12){ day=1; while (day<365){ item=new linearlayout(this); item.setlayoutparams(new layoutparams(layoutparams.match_parent, layoutparams.match_parent)); //item.settag(current date); mycalendarview.addview(item); day=day+1; } month=month+1; } year=year+1; }
you not need show 1400 linearlayouts @ once on screen. create views appear on screen , recycle views have dissappeared screen.
if want user input data specific day, , save/load data, need kind of data model database.
Comments
Post a Comment