radiobutton getleft()在重新填充

时间:2015-08-04 19:08:30

标签: java android

我有一个带数据库填充的radiobuttons的radiogroup。当我用以下方式重新填充它们时:

Radiogroup fofo = (Radiogroup) findViewById(R.id.AperturasRadio);
    fofo.removeAllViews();
    for(int i = 0; i < mStringArray.length ; i++){
            RadioButton newRadioButton;
            newRadioButton = (RadioButton)
            getLayoutInflater().inflate(R.layout.radio_template, null);
            String label = (String) mStringArray[i];
            newRadioButton.setText(label);
            newRadioButton.setId(i);
            if (label.equals("2.8")) {
                newradiobutton.setChecked(true);
            }
            fofo.addView(newRadioButton);
            fofo.updateBackground();

问题是我有一个RadioGroup.OnCheckedChangeListener,它触发了一个需要CheckedRadiobutton.Getleft()的不同方法

    RadioGroup.OnCheckedChangeListener listenerAperturas = new RadioGroup.OnCheckedChangeListener() {
                public void onCheckedChanged(RadioGroup group, int id) {

RadioGroup grupo1 = (RadioGroup) findViewById(R.id.AperturasRadio);
int radioButtonID = grupo1.getCheckedRadioButtonId();
RadioButton radiogrButton = (RadioButton) findViewById(radioButtonID);
int left = radiogrButton.getLeft();
Toast.makeText(getApplicationContext(), "Botton radio: " + left + " " , Toast.LENGTH_SHORT).show();

但值为0.第一次放射组填充工作正常,但是当我触发de repopulation时,返回零。

布局如下:

<HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/horiz"
            android:scrollbars="none">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Space
        android:layout_width="500px"
        android:layout_height="match_parent" />

            <com.alfbishop.testing.testbbdd.ListasBotones
            android:id="@+id/AperturasRadio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="41dp"
            android:orientation="horizontal">
     </com.alfbishop.testing.testbbdd.ListasBotones>
    <Space
        android:layout_width="500px"
        android:layout_height="match_parent" />
</LinearLayout>
        </HorizontalScrollView>

你能帮我找一个解决方案吗?

0 个答案:

没有答案