I am doing an inventory management Android app where I am programmatically and dynamically creating rows to put in my xml-defined tablelayout. For every item, I create a tablerow containing 2 views: a textview containing the name of the inventory item, and a radiogroup containing 3 radiobuttons: present, missing, and repairs needed. There is also a linearlayout below each row in the tablelayout that contains a textview and an edittext, but that part isn't having any issues.
This is my screenshot showing what it currently looks like: https://preview.ibb.co/k8a7Yw/Screenshot_20171011_170618.png
Right now, the radio buttons display fine on my phone screen (after setting shrinkcolumn=0 in the xml for the tablelayout so the text of the 3rd radiobutton doesn't get cut off), but the item name gets squished. What I would like to happen is to move the last radio button (repairs needed) down a line, but keep it in the radiogroup and row so I don't have to go through creating custom classes inheriting from radiogroup to get it to toggle right.
Current code:
public class PMR {
String result;
String caption;
String repairString;
EditText repairEditText;
RadioButton pRadioButton;
RadioButton mRadioButton;
RadioButton rRadioButton;
public PMR(){
}
public PMR(final TableLayout tableLayout, final TableRow tableRow,
final Context context, String caption){
this.caption=caption;
result="incomplete";
repairString=null;
final RadioGroup radioGroup=new RadioGroup(context);
radioGroup.setTag("incomplete");
radioGroup.setOrientation(RadioGroup.HORIZONTAL);
tableRow.addView(radioGroup);
pRadioButton = new RadioButton(context);
pRadioButton.setText("Present");
pRadioButton.setId(generateViewId());
final int pId=pRadioButton.getId();
mRadioButton = new RadioButton(context);
mRadioButton.setText("Missing");
mRadioButton.setId(generateViewId());
final int mId=mRadioButton.getId();
rRadioButton = new RadioButton(context);
rRadioButton.setText("Repairs Needed");
rRadioButton.setId(generateViewId());
final int rId=rRadioButton.getId();
radioGroup.addView(pRadioButton);
radioGroup.addView(mRadioButton);
radioGroup.addView(rRadioButton);
final LinearLayout textLayout=new LinearLayout(context);
textLayout.setOrientation(LinearLayout.HORIZONTAL);
tableLayout.addView(textLayout);
textLayout.setTag("Text Row");
final TextView labelText = new TextView(context);
labelText.setText("");
textLayout.addView(labelText);
repairEditText = new EditText(context);
repairEditText.setEnabled(false);
repairEditText.setText("");
textLayout.addView(repairEditText);
final String prefix="Notes: ";
radioGroup.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged (RadioGroup group,
int checkedId){
if (checkedId!=rId &&
repairEditText.getText().toString()!=null){
repairString=repairEditText.getText().toString();
}
if (checkedId == pId) {
result="Present";
repairEditText.setText("");
repairEditText.setEnabled(false);
labelText.setText("");
radioGroup.setTag("pTag");
} else if (checkedId == mId) {
result="Missing";
repairEditText.setText("");
repairEditText.setEnabled(false);
labelText.setText("");
radioGroup.setTag("mTag");
} else if (checkedId == rId) {
result="Repairs Needed";
if (repairString!=null){
repairEditText.setText(repairString);
}
repairEditText.setEnabled(true);
repairEditText.requestFocus();
labelText.setText(prefix);
radioGroup.setTag("rTag");
}
else {
result = "incomplete";
radioGroup.setTag("incomplete");
}
}
});
}
}
With the tablelayout xml:
<TableLayout
android:id="@+id/tableLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle"
android:shrinkColumns="0"
>
</TableLayout>
This is basically what I am trying to get my tablerows to look like: https://image.ibb.co/i5qrtw/goodtablerowpmr.png