java - Utilizing 2 Layouts within a ListView -
i have been trying implement listview utilizes 2 seperate layouts depending on row. first layout has 1 imageview, , second layout has 2 imageviews.
i make can each row within listview contain alternating layouts, able use in arraylist bitmaparray;
so example, first row contain first 2 bitmap images, , second row contain 1 large bitmap image, 3rd row 2 more bitmap images side side... , forth.
update
i have got working somewhat, , issue remains images not being seperated properly. reusing total of 4 different pictures , seperating them oddly... try illustrate below
each number represents picture in bitmaparray (there 20 images total 0 - 19)
needs be
[ 0 ] [ 1 , 2 ] [ 3 ] [ 4, 5 ] [ 6 ] [ 7, 8 ] [ 9 ] [10 , 11] [ 12 ] [13, 14] [ 15 ] [16, 17] [ 18 ] [ 19, --]
updated pattern der golem
[ 0 ] [ 1 , 2 ] [ 2 ] [ 3 , 4 ] repeat
**there ever total of 20 images stored in bitmaparray. issue finding when press onitemclick on later row (say 10) take me activity bitmap enlarged ( designed ).. weird thing totally different image, 1 corresponds position in array. **
here code have been working with. public class feedadapter extends arrayadapter<bitmap> { private static final int type_big_item = 0; private static final int type_small_item = 1; public feedadapter(context context, arraylist<bitmap> bitmaparray) { super(context, r.layout.feed_listview_big); } private class viewholder { imageview ivpicturesmallone; imageview ivpicturesmalltwo; imageview ivpicturebig; } @override public int getviewtypecount() { return 2; } @override public int getitemviewtype(int position) { return position % 2; } @override public view getview(int position, view convertview, viewgroup parent) { bitmap bmp = getitem(position); viewholder viewholder; if (convertview == null) { viewholder = new viewholder(); layoutinflater inflater = layoutinflater.from(getcontext()); if (getitemviewtype(position) == 0) { convertview = inflater.inflate(r.layout.feed_listview_small, null); viewholder.ivpicturesmallone = (imageview) convertview .findviewbyid(r.id.ivsmall1); viewholder.ivpicturesmalltwo = (imageview) convertview .findviewbyid(r.id.ivsmall2); viewholder.ivpicturesmallone.setimagebitmap(bmp); viewholder.ivpicturesmalltwo.setimagebitmap(getitem(position + 1)); } else { convertview = inflater.inflate(r.layout.feed_listview_big, null); viewholder.ivpicturebig = (imageview) convertview .findviewbyid(r.id.ivbig); viewholder.ivpicturebig.setimagebitmap(bmp); } } // return completed view render on screen return convertview; } }
try changing this
if (convertview == null) { viewholder = new viewholder(); layoutinflater inflater = layoutinflater.from(getcontext()); if (getitemviewtype(position) == 0) { convertview = inflater.inflate(r.layout.feed_listview_small, null); viewholder.ivpicturesmallone = (imageview) convertview .findviewbyid(r.id.ivsmall1); viewholder.ivpicturesmalltwo = (imageview) convertview .findviewbyid(r.id.ivsmall2); viewholder.ivpicturesmallone.setimagebitmap(bmp); viewholder.ivpicturesmalltwo.setimagebitmap(getitem(position + 1)); } else { convertview = inflater.inflate(r.layout.feed_listview_big, null); viewholder.ivpicturebig = (imageview) convertview .findviewbyid(r.id.ivbig); viewholder.ivpicturebig.setimagebitmap(bmp); } } // return completed view render on screen return convertview;
to
if (convertview == null) { viewholder = new viewholder(); layoutinflater inflater = layoutinflater.from(getcontext()); // every 3rd image, load "big" 1 if ((getitemviewtype(position) % 3) == 0) { convertview = inflater.inflate(r.layout.feed_listview_big, null); viewholder.ivpicturebig = (imageview) convertview .findviewbyid(r.id.ivbig); viewholder.ivpicturebig.setimagebitmap(bmp); } // if not dividable 3, load 2 "small" ones else { convertview = inflater.inflate(r.layout.feed_listview_small, null); viewholder.ivpicturesmallone = (imageview) convertview .findviewbyid(r.id.ivsmall1); viewholder.ivpicturesmalltwo = (imageview) convertview .findviewbyid(r.id.ivsmall2); viewholder.ivpicturesmallone.setimagebitmap(bmp); viewholder.ivpicturesmalltwo.setimagebitmap(getitem(position + 1)); } } // return completed view render on screen return convertview;
Comments
Post a Comment