我在單選按鈕和複選框按鈕上工作。值0爲無線電,1爲複選框。基於這些值,我想在屏幕上顯示它。可能有收音機和複選框。根據數據庫值顯示單選按鈕和複選框
現在,值從數據庫中獲得0和1,它只是設置單選按鈕或複選框的所有屬性。它應該顯示爲值1和單選按鈕複選框值的0。
下面是代碼:
if(multiSelect != null)
{
RadioButton radioButton = new RadioButton(mMain);
radioButton.setText(name_price);
radioButton.setId(i + 6);
radioButton.setTextSize(12);
radioButton.setTag(attributes.get(num));
radioButton.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
{
radioButton.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
}
setTextFont(radioButton, "Museo_Slab.otf");
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
1f);
lp.setMargins(10, 10, 0, 10); // llp.setMargins(left, top, right, bottom);
radioButton.setLayoutParams(lp);
attr_layout[j].addView(radioButton);
num++;
radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
try
{
ItemAttributes itemAttributes = (ItemAttributes) buttonView.getTag();
if (isChecked)
{
float total_price = current_price + attr_price;
item.setItemPrice(total_price + "");
item_price_text.setText(priceStr);
selectedAttributes.add(itemAttributes);
}
// If the attributes are not checked
} catch (Exception ex)
{
GSLogger.e(ex);
}
}
});
}
else // if the multiSelect is 1
{
CheckBox checkBox = new CheckBox(mMain);
checkBox.setText(name_price);
checkBox.setId(i + 6);
checkBox.setTextSize(12);
checkBox.setTag(attributes.get(num));
checkBox.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
{
checkBox.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
}
setTextFont(checkBox, "Museo_Slab.otf");
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
1f);
lp.setMargins(10, 10, 0, 10); // llp.setMargins(left, top, right, bottom);
checkBox.setLayoutParams(lp);
attr_layout[j].addView(checkBox);
num++;
// Reads the value depending on attribute User Selects
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
try
{
ItemAttributes itemAttributes = (ItemAttributes) buttonView.getTag();
if (isChecked)
{
float total_price = current_price + attr_price;
item.setItemPrice(total_price + "");
item_price_text.setText(priceStr);
selectedAttributes.add(itemAttributes);
}
} catch (Exception ex)
{
GSLogger.e(ex);
}
}
});
}
}
}
}
基於定義的項目組說它是0或1,它應該在屏幕上顯示它。如果組有兩個選項,則屏幕應顯示0值的無線電和1值的複選框。
你正面臨什麼樣的問題? –