Question

as shown in image i need to set text view LEFT OF RADIO GROUP and i did it using java code....so i don't know to set parameter for LAYOUT LEFT OF="" in java code.....how to solve it ..please guide me this way...

enter image description here

this is class file......

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rate_me_up);
    textViewShowTime = (TextView) findViewById(R.id.tvTimeCount);
    layout = (RelativeLayout) findViewById(R.id.linear);

    Button btnp = (Button) findViewById(R.id.buttonp);
    btnp.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    RadioGroup radioGroup = new RadioGroup(Rate_me_up.this);
    radioGroup.setOrientation(0);

    RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    if (mLastRadioGroup != null)
        p.addRule(RelativeLayout.BELOW, mLastRadioGroup.getId());

    radioGroup.setId(mRadioGroupId++);
    mLastRadioGroup = radioGroup;
    layout.addView(radioGroup, p);
    RadioButton radioButtonView = new RadioButton(Rate_me_up.this);
    radioButtonView.setText("radio1");
    radioButtonView.setId(id++);
    radioButtonView.setButtonDrawable(R.drawable.e404);
    radioButtonView.setChecked(false);
    radioGroup.addView(radioButtonView, p);

    RadioButton radioButtonView2 = new RadioButton(Rate_me_up.this);
    radioButtonView2.setText("radio2");
    radioButtonView2.setId(id++);
    radioButtonView2.setChecked(false);
    radioGroup.addView(radioButtonView2, p);
    RadioButton radioButtonView3 = new RadioButton(Rate_me_up.this);
    radioButtonView3.setText("radio3");
    radioButtonView3.setId(id++);
    radioGroup.addView(radioButtonView3, p);
    radioButtonView3.setChecked(false);
    TextView txt = new TextView(Rate_me_up.this);

    txt.setText("FOOD QUALITY!");
    layout.addView(txt, p);

    radioGroup.setOnCheckedChangeListener(this);

}
Was it helpful?

Solution

Alright you can do it by this way:

TextView txt = new TextView(Rate_me_up.this);
txt.setText("FOOD QUALITY!");
RelativeLayout.LayoutParams params=
         new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
               LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.LEFT_OF,radiofroup.getId());
txt.setLayoutParams(params);
layout.addView(txt);

Hope I answered your question. :)

OTHER TIPS

addRule Do something like this..

 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)button.getLayoutParams();
 params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
 params.addRule(RelativeLayout.LEFT_OF, R.id.id_to_be_left_of);
 button.setLayoutParams(params);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top