2013-06-05 3 views
0

동적으로 textview 및 radiobutton 동적 레이아웃을 포함하는 상대 레이아웃을 만들었습니다.이 레이아웃을 목록 뷰 행에 전개해야합니다. 채울동적으로 생성 된 상대 레이아웃을 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(); 
     } 
    }); 

필요 목록보기 행이 동적으로 생성 된 상대 레이아웃

+0

getView() 방법 http://izvornikod.com/Blog/tabid/82에 코드를 추가합니다 /EntryId/8/Creating-Android-button-with-image-and-text-using-relative-layout.aspx – RanjitRock

답변

0

ListViewAdapter

관련 문제