I am creating multiple radio group for each record that is fetch from database. I am creating an attendance portal in which I want to add two radio button for each student as a group. I am unable to create logic for that can you tell me how to implement the code for that? Names are showing on output but radio button group is not creating for names.
TableRow rowHeader = new TableRow(this);
rowHeader.setBackgroundColor(Color.parseColor("#FFDBAA"));
rowHeader.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
String[] headerText={"NAME","PRESENT","ABSENT","OTHER"};
for(String c:headerText)
{
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv.setGravity(Gravity.CENTER);
tv.setTextSize(18);
tv.setTextColor(Color.parseColor("#553100"));
tv.setPadding(7, 7, 7, 7);
tv.setText(c);
rowHeader.addView(tv);
}
tableLayout.addView(rowHeader);
Cursor c = SDB.rawQuery("select * from student where Course='" + course + "'", null);
t2.setText(" "+course+"\n");
t1.setText(" "+formattedDate);
if (c.getCount() > 0)
{
while(c.moveToNext())
{
// Toast.makeText(this,c.getString(1), Toast.LENGTH_SHORT).show();
String name = c.getString(c.getColumnIndex("Name"));
TableRow row = new TableRow(this);
row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv.setGravity(Gravity.CENTER);
tv.setTextSize(16);
tv.setPadding(7, 7, 7, 7);
tv.setText(name);
tv.setId(i);
i=i+1;
row.addView(tv);
tableLayout.addView(row);
RadioButton radioButton1 = new RadioButton(this);
radioButton1.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
radioButton1.setId(0);
RadioButton radioButton2 = new RadioButton(this);
radioButton2.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
radioButton2.setId(1);
RadioGroup radioGroup = new RadioGroup(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(40, 0, 0, 0);
radioGroup.setLayoutParams(params);
radioGroup.addView(radioButton1);
radioGroup.addView(radioButton2);
row.addView(radioGroup);
}
}
I expect on right hand side of each name there should be 2-3 radio buttons that will be dependent.
答案 0 :(得分:0)
I think you just forgot to assign the Buttons to the group