Depending on the project requirements, you want to load the control dynamically, Imageview,radiobutton
Sample
1. Dynamic load ImageView
Show existing pictures, calculate number of pictures
Here IMGs is a list array of pictures
private void Initphotos (View V, Hashmap<integer, string> IMGs) {
Linearlayout.layoutparams LP = new Linearlayout.layoutparams (
(GETWIDTHPX ()-2)/3, (GETWIDTHPX ()-20 * 2)/4);
int Imgcount = (IMGs = = NULL | | imgs.size () = = 0)? 0: (Imgs.size () > 3 3:imgs.size ());
for (int i = 0; i < Imgcount; i++) {
ImageView img = (ImageView) v.findviewwithtag ("img" + i);
Mapplication.get (). GetImageLoader2 (). DisplayImage (Imgs.get (i), IMG);
Img.setvisibility (view.visible);
IMG.SETLAYOUTPARAMS (LP);
}
IMGLAYOUT1.SETLAYOUTPARAMS (LP);
IMGLAYOUT2.SETLAYOUTPARAMS (LP);
IMGLAYOUT3.SETLAYOUTPARAMS (LP);
}
XML file
<linearlayout
Android:id= "@+id/level_imglayout2d"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
android:background= "@drawable/LEVELUP_UDLR"
Android:gravity= "Center_vertical"
android:orientation= "Horizontal"
Android:padding= "3DP"
android:visibility= "Invisible" >
<imageview
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:layout_marginleft= "2DP"
Android:scaletype= "Fitxy"
android:tag= "@+tag/img1"/>
</LinearLayout>
Sample2
Dynamic load RadioButton
Private Radiogroup RG;
protected void Oninitlayout (view view) {
RG = (Radiogroup) View.findviewbyid (R.id.qualityradiogroup);
Rg.setoncheckedchangelistener (this);
In fragment, it is more convenient to add temporary data using shareedpreference
Sharepreference = Lsharepreference.getinstance (Getactivity ());
Send JSON
Sendqualityconditionjson ();
}
Add RadioButton Dynamically
private void SetData () {
for (int i = 0; i < mdata.size (); i++) {
Final RadioButton RadioButton = new RadioButton (getactivity ());
Radiobutton.settext (Mdata.get (i). Name);
Radiobutton.settextcolor (Color.Black);
Radiobutton.setbuttondrawable (R.drawable.radio_button_selector);
Radiobutton.setpadding (55, 10, 10, 10);
Radiobutton.settag (i);
Radiobutton.setid (3020 + i);
if (! Lformat.isempty (sharepreference.getstring ("Quality_condition"))) {
if (i = = Integer.parseint (sharepreference.getstring ("Quality_condition"))-3020-2) {
Radiobutton.setchecked (TRUE);
}
}else if (i==0) {
Radiobutton.setchecked (TRUE);
}
Rg.addview (RadioButton);
Radiobutton.setonclicklistener (this);
}
Rg.setoncheckedchangelistener (this);
}
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
The ID, minus 3020, is the data index in the original list.
Sharepreference.setstring ("Quality_condition",
Mdata.get (V.getid ()-3020). ID + "");
L.E (sharepreference.getstring ("Quality_condition", ""));
}
Android for dynamic load Imageview,radiobutton