android - Wallpaper App Code Optimazation -


hey friend making wallpaper app using bitmap.. have more 50 images app...the problem facing have add line of code images in java code xml file...

so please let me know there way overcome adding loop or something...anything can reduce code , can add more images...

the java code repeating is(just few line getting repeated) :

display = (imageview) findviewbyid(r.id.ivdisplay);     imageview image1 = (imageview) findviewbyid(r.id.viewimage1);     imageview image2 = (imageview) findviewbyid(r.id.viewimage2);     imageview image3 = (imageview) findviewbyid(r.id.viewimage3);     imageview image4 = (imageview) findviewbyid(r.id.viewimage4);     imageview image5 = (imageview) findviewbyid(r.id.viewimage5);     imageview image6 = (imageview) findviewbyid(r.id.viewimage6);     imageview image7 = (imageview) findviewbyid(r.id.viewimage7);     imageview image8 = (imageview) findviewbyid(r.id.viewimage8);     imageview image9 = (imageview) findviewbyid(r.id.viewimage9); 

so on

then after again in java code itself

tophone = r.id.ivdisplay;      image1.setonclicklistener(this);     image2.setonclicklistener(this);     image3.setonclicklistener(this);     image4.setonclicklistener(this);     image5.setonclicklistener(this);     image6.setonclicklistener(this);     image7.setonclicklistener(this);     image8.setonclicklistener(this);     image9.setonclicklistener(this); 

so on

then in switch case have repeat code again

switch (v.getid()){      case r.id.viewimage1:         display.setimageresource(r.drawable.a);         tophone = r.drawable.a;         break;     case r.id.viewimage2:         display.setimageresource(r.drawable.b);         tophone = r.drawable.b;         break;     case r.id.viewimage3:         display.setimageresource(r.drawable.c);         tophone = r.drawable.c;         break;     case r.id.viewimage4:         display.setimageresource(r.drawable.d);         tophone = r.drawable.d;         break;     case r.id.viewimage5:         display.setimageresource(r.drawable.e);         tophone = r.drawable.e;         break;     case r.id.viewimage6:         display.setimageresource(r.drawable.f);         tophone = r.drawable.f;         break;     case r.id.viewimage7:         display.setimageresource(r.drawable.g);         tophone = r.drawable.g;         break;     case r.id.viewimage8:         display.setimageresource(r.drawable.h);         tophone = r.drawable.h;         break; 

and on

case r.id.setbg:              bitmap bmap = bitmapfactory.decodestream(getresources().openrawresource(tophone));                try{                     getapplicationcontext().setwallpaper(bmap);                }catch(ioexception e){                    e.printstacktrace();                } 

now coming xml parth there have add images...

<linearlayout         android:layout_width="150dp"         android:layout_height="wrap_content"         android:orientation="horizontal" >          <imageview             android:id="@+id/viewimage1"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/a" />          <imageview             android:id="@+id/viewimage2"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/b" />          <imageview             android:id="@+id/viewimage3"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/c" />          <imageview             android:id="@+id/viewimage4"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/d" />          <imageview             android:id="@+id/viewimage5"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/e" />          <imageview             android:id="@+id/viewimage6"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/f" />          <imageview             android:id="@+id/viewimage7"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/g" />          <imageview             android:id="@+id/viewimage8"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/h" />          <imageview             android:id="@+id/viewimage9"             android:layout_width="125dp"             android:layout_height="150dp"             android:padding="15dp"             android:src="@drawable/i" /> 

and on code images...

friends please dont give negative rating...i have made app there 51 images , have write code 51...i want optimize app can add more images , learn new thing. hope come , me optimization thing...

thanks


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -