Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- table row selection error in scrollview
- public class TabActivity extends Activity {
- TableLayout table;
- RadioGroup mRadioGroup;
- ArrayList<String> list_name;
- int color_blue = -16776961;
- int color_gray = -7829368;
- int color_black = -16777216;
- int color_white = -1;
- final int CHECK_BUTTON_ID = 982301;
- int ids_check[];
- boolean bool_check[];
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- table = (TableLayout) findViewById(R.id.tableLayout1);
- list_name = new ArrayList<String>();
- list_name.add("Close");
- list_name.add("Cristiano");
- list_name.add("David");
- list_name.add("Fernando");
- list_name.add("Messi");
- list_name.add("Kaka");
- list_name.add("Wayne");
- list_name.add("use");
- list_name.add("e");
- list_name.add("eff");
- list_name.add("euyr");
- list_name.add("ejjyytuty");
- list_name.add("madre");
- list_name.add("yuir");
- list_name.add("eyrty");
- list_name.add("etytr");
- list_name.add("ewrrtt");
- bool_check = new boolean[list_name.size()];
- ids_check = new int[list_name.size()];
- createTableRows();
- }
- public void createTableRows()
- {
- for (int i = 0; i < list_name.size(); i++)
- {
- final TableRow table_row = new TableRow(this);
- TextView tv_name = new TextView(this);
- Button btn_check = new Button(this);
- ImageView img_line = new ImageView(this);
- table_row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
- table_row.setBackgroundColor(color_black);
- table_row.setGravity(Gravity.CENTER_HORIZONTAL);
- // table_row.setFocusable(true);
- mRadioGroup = new RadioGroup(this);
- // test adding a radio button programmatically
- final RadioButton[] mbutton=new RadioButton[7];
- for(int l=0;l<7;l++){
- mbutton[l]=new RadioButton(this);
- mbutton[l].setText("test"+l);
- mRadioGroup.addView(mbutton[l]);
- }
- // LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
- // RadioGroup.LayoutParams.WRAP_CONTENT,
- // RadioGroup.LayoutParams.WRAP_CONTENT);
- // mRadioGroup.addView(newRadioButton);
- tv_name.setText((CharSequence) list_name.get(i));
- tv_name.setTextColor(color_blue);
- tv_name.setTextSize(30);
- tv_name.setTypeface(Typeface.DEFAULT_BOLD);
- tv_name.setWidth(150);
- btn_check.setLayoutParams(new LayoutParams(30, 30));
- btn_check.setBackgroundResource(R.drawable.small_checkbox_unchecked);
- img_line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 2));
- img_line.setBackgroundResource(R.drawable.separater_line);
- table_row.addView(tv_name);
- table_row.addView(btn_check);
- table_row.addView(mRadioGroup);
- table.addView(table_row);
- table.addView(img_line);
- //table.addView(mRadioGroup);
- mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- public void onCheckedChanged(RadioGroup mRadioGroup, int checkedId) {
- for(int i=0; i<mRadioGroup.getChildCount(); i++) {
- RadioButton btn = (RadioButton) mRadioGroup.getChildAt(i);
- int t=table.indexOfChild(table_row);
- System.out.println(t);
- if(btn.getId() == checkedId) {
- String text = btn.getText().toString();
- // do something with text
- Log.d(text," event1");
- return;
- }
- }
- }
- });
- }
- }
- }
Add Comment
Please, Sign In to add comment