First
Use Java directly with XML (First, the most important .. Second, I think too much)
<Imageview Android: Id = "@ + ID/qqicon" Android: layout_margintop = "15dip" Android: layout_gravity = "center" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"/> <! -- QQ icon -->
Java
IMG = (imageview) findviewbyid (R. id. qqicon); IMG. setimageresource (R. drawable. qq_c); // use the if statement to control the changes of the image ....... QB = B. getint ("qb", QB); // display the corresponding qcoin image switch (QB) {Case 1: IMG. setimageresource (R. drawable. QB1); // 1q currency break; Case 5: IMG. setimageresource (R. drawable. qb5); // 5q currency break; case 10: IMG. setimageresource (R. drawable. qb10); // 10q currency break; case 20: IMG. setimageresource (R. drawable. qb20); // 20q currency break ;}
Second
The Java code is basically used, but the XML
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id = "@+id/Linear_QQicon" >
Linear_qq = (linearlayout) findviewbyid (R. id. linear_qqicon); linearlayout llT = new linearlayout (activityexchange_qq_commit.this); linearlayout. layoutparams Params = new linearlayout. layoutparams (layoutparams. wrap_content, layoutparams. wrap_content); Params. gravity = gravity. center; imageview IMG = new imageview (activityexchange_qq_commit.this); IMG = (imageview) findviewbyid (R. id. qqicon); IMG. setimageresource (R. drawable. qq_c); // use the if statement to control the changes of the image. // linear_qq.addview (IMG, Params); QB = B. getint ("qb", QB); // display the corresponding qcoin image switch (QB) {Case 1: IMG. setimageresource (R. drawable. QB1); // 1q currency break; Case 5: IMG. setimageresource (R. drawable. qb5); // 5q currency break; case 10: IMG. setimageresource (R. drawable. qb10); // 10q currency break; case 20: IMG. setimageresource (R. drawable. qb20); // 20q currency break ;}