0
我已經動態創建了一個包含textview和radiobutton的相對佈局動態。現在我需要將此佈局充氣到listview行。如何將動態生成的相對佈局充氣到Listview行?
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
txt = new TextView(context);
txt.setId(1001);
txt.setText("Question");
txt.setTextColor(Color.BLACK);
txt.setTextSize(5);
txt.setLayoutParams(params);
RelativeLayout.LayoutParams quesParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
quesParams.addRule(RelativeLayout.BELOW,1001);
quesParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
TextView txtQues = new TextView(context);
txtQues.setId(1010);
txtQues.setText("What is the oldest civilization on earth?");
txtQues.setTextSize(10);
txtQues.setTextColor(Color.BLUE);
txtQues.setLayoutParams(quesParams);
RadioButton rdp = new RadioButton(context);
rdp.setText("Harrapa");
rdp.setTextColor(Color.BLACK);
rdp.setTextSize(10);
RadioButton rd2 = new RadioButton(context);
rd2.setText("Egypt");
rd2.setTextColor(Color.BLACK);
rd2.setTextSize(10);
RadioButton rd3 = new RadioButton(context);
rd3.setText("Egypt");
rd3.setTextColor(Color.BLACK);
rd3.setTextSize(10);
RadioButton rd4 = new RadioButton(context);
rd4.setText("kumarikandam");
rd4.setTextColor(Color.BLACK);
rd4.setTextSize(10);
RelativeLayout.LayoutParams radioGrpparms = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
radioGrpparms.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
radioGrpparms.addRule(RelativeLayout.BELOW, 1010);
rdgrp = new RadioGroup(context);
rdgrp.setLayoutParams(radioGrpparms);
rdgrp.addView(rdp, radioGrpparms);
rdgrp.addView(rd2, radioGrpparms);
rdgrp.addView(rd4, radioGrpparms);
RelativeLayout rel = new RelativeLayout(context);
rel.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.FILL_PARENT));
rel.addView(txt);
rel.addView(txtQues);
rel.addView(rdgrp);
rel.setId(1050);
//setContentView(rel);
rdgrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton view=(RadioButton)findViewById(checkedId);
Toast.makeText(context,view.getText() , Toast.LENGTH_LONG).show();
}
});
需要將填充這個動態生成相對佈局的ListView行
的
getView()
方法http://izvornikod.com/Blog/tabid/82 /EntryId/8/Creating-Android-button-with-image-and-text-using-relative-layout.aspx – RanjitRock