java - Skipped 46 frames! The application may be doing too much work on its main thread -
i'm trying use recyclerview , put 8 images in adapter dynamically. have titles of each image create 2 arrays , loop multiple condition can set want. works not want. infact in log:
skipped 46 frames! application may doing work on main thread.
and scroll of list has strong lag. how can solve? code
public class imageadapter extends recyclerview.adapter<imageadapter.viewholder> { list<griditem> mitems; private static wallpapermanager wallpaper; string[] title = { "material1", "material2", "wallpaper1", "wallpaper2", "wallpaper3", "wallpaper4", "wallpaper5", "wallpaper6", "wallpaper7" }; private static int[] sdrawables = { r.drawable.material, r.drawable.materialuno, r.drawable.materialdue, r.drawable.materialtre, r.drawable.materialquattro, r.drawable.materialcinque, r.drawable.materialsei, r.drawable.materialsette, r.drawable.materialotto }; public imageadapter() { super(); mitems = new arraylist<griditem>(); (int i=0, j=0; < title.length && j < sdrawables.length; i++, j++) { griditem walltitle = new griditem(); walltitle.setname(title[i]); walltitle.setthumbnail(sdrawables[j]); mitems.add(walltitle); } } @override public viewholder oncreateviewholder(viewgroup viewgroup, int i) { view v = layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.image_grid_layout, viewgroup, false); viewholder viewholder = new viewholder(v); return viewholder; } @override public void onbindviewholder(viewholder viewholder, final int i) { final griditem nature = mitems.get(i); viewholder.tvspecies.settext(nature.getname()); viewholder.imgthumbnail.setimageresource(nature.getthumbnail()); viewholder.imgthumbnail.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.i("click",nature.tostring()); } }); } @override public int getitemcount() { return mitems.size(); } class viewholder extends recyclerview.viewholder{ public imageview imgthumbnail; public textview tvspecies; public viewholder(view itemview) { super(itemview); imgthumbnail = (imageview)itemview.findviewbyid(r.id.img_thumbnail); tvspecies = (textview)itemview.findviewbyid(r.id.tv_species); } } }
edited entire adapter
the real walls web array of drawable array of links or json
you absolutely not want loading full-size wallpaper images use thumbnails in grid. slow, , run out of heap space.
for short-term tests, i'd prepare thumbnails using graphics editor, use those.
for "for realz" app, wallpapers downloaded, want use third-party library, picasso or universal image loader, can load images in background, downsample them thumbnail size, , on. this sample app demonstrates listview
picasso (reading in stack overflow questions). this sample app demonstrates recyclerview
universal image loader (reading in video thumbnails videos on device).
Comments
Post a Comment