java - OutOfMemoryError error when changing the tint color of Vector images -


i have @ least 48 small images displaying vector images stored xml file in drawable. have multi choice listview 48 items. when item checked access image counterpart , change tint of image. if less (approximately) 30 items checked, there no problem, if it's more that, outofmemoryerror displayed. here example of code:

   view.onclicklistener listener= new view.onclicklistener() {            @override            public void onclick(view v) {                sparsebooleanarray checked = listview.getcheckeditempositions();                (int = 0; < checked.size(); i++) {                    // item position in adapter                    int position = checked.keyat(i);                    // add sport if checked i.e.) == true!                    image = null;                    if (checked.valueat(i)) {                        switch (position) {                            case 1:                                image = (imageview) findviewbyid(r.id.image1);                                image.setcolorfilter(r.color.green);                                break;                            case 2:                                image = (imageview) findviewbyid(r.id.image2);                                image.setcolorfilter(r.color.green);                                break;                            case 3:                                image = (imageview) findviewbyid(r.id.image3);                                image.setcolorfilter(r.color.green);                                break;                             ....                             case:48                                image = (imageview) findviewbyid(r.id.image48);                                image.setcolorfilter(r.color.green);                                break;                                }                            }                      }  mybutton.onclicklistener(listener) 

example of images in xml file

<relativelayout>         <imageview             android:layout_width="400dp"             android:layout_height="400dp"             android:src="@drawable/img45"             android:id="@+id/image1"             />         <imageview             android:layout_width="400dp"             android:layout_height="400dp"             android:src="@drawable/img45"             android:id="@+id/image2"             /> ....         <imageview             android:layout_width="400dp"             android:layout_height="400dp"             android:src="@drawable/img45"             android:id="@+id/image48"             /> </relativelayout> 

it seems problem common bitmap images, solution proposed in previous questions not suit case. think if change src of images xml vector simple png fix problem? if not, suggestion?

you're creating separate color filter each image. creating single color filter , using on images reduce object usage. if image view creating new bitmap shading you're going go oom no matter what- you're creating 48 new bitmaps here, huge amount of memory.

secondly, every time check single item, you're creating new filters images. that's horribly inefficient (especially since have n time searches in each case) , make problems in previous paragraph worse. change single item clicked in each click handler. doing war creates sum (i=1 n) new images n number of images clicked- n=30 that's 430ish.

as aside- using switch statement here horrible. create array of imageviews @ start time , index array, rather using findviewbyid each time o(n) search through view tree. code pretty bad around.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -