Is it a good thing to write logic based on the hex value of id generated in R.java android -
this have seen in android application. have number of image buttons ids
r.java : public static final int img1=0x7f090080; public static final int img2=0x7f090081; public static final int img3=0x7f090082; public static final int img4=0x7f090083; public static final int img5=0x7f090084; public static final int img6=0x7f090085; public static final int img7=0x7f090086; public static final int img8=0x7f090087;
in 1 of activity traversing loop below:
for (int = 0; < noofbuttons; i++) { if (i == pos) { ((imageview) vi.findviewbyid(r.id.img1 + i)).setimageresource(r.drawable.circular_pagination_red); } else { ((imageview) vi.findviewbyid(r.id.img1 + i)).setimageresource(r.drawable.circular_pagination_brown); }
i want know how safe , advisable is. 1 thing working absolutely fine. been part of months , never seen problem in logic. still irks me bit.
note : not getting error , know alternate solution also. concern if not advisable/safe want know why? scenarios can create havoc me. have understanding r.java.
though might work ok of times, not advisable. r class generated automatically have no control on , change. there solution problem using typed array in resources. check example this answer.
Comments
Post a Comment