daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. table row selection error in scrollview
  2. public class TabActivity extends Activity {
  3. TableLayout table;
  4. RadioGroup  mRadioGroup;
  5. ArrayList<String> list_name;
  6.  
  7. int color_blue = -16776961;
  8. int color_gray = -7829368;
  9. int color_black = -16777216;
  10. int color_white = -1;
  11.  
  12. final int CHECK_BUTTON_ID = 982301;
  13. int ids_check[];
  14. boolean bool_check[];
  15.  
  16.  
  17. /** Called when the activity is first created. */
  18. @Override
  19. public void onCreate(Bundle savedInstanceState) {
  20.     super.onCreate(savedInstanceState);
  21.    setContentView(R.layout.main);
  22.    table = (TableLayout) findViewById(R.id.tableLayout1);
  23.  
  24.    list_name = new ArrayList<String>();
  25.  
  26.    list_name.add("Close");
  27.    list_name.add("Cristiano");
  28.    list_name.add("David");
  29.    list_name.add("Fernando");
  30.    list_name.add("Messi");
  31.    list_name.add("Kaka");
  32.    list_name.add("Wayne");
  33.  
  34.    list_name.add("use");
  35.    list_name.add("e");
  36.    list_name.add("eff");
  37.    list_name.add("euyr");
  38.    list_name.add("ejjyytuty");
  39.    list_name.add("madre");
  40.    list_name.add("yuir");
  41.    list_name.add("eyrty");
  42.    list_name.add("etytr");
  43.    list_name.add("ewrrtt");
  44.  
  45.    bool_check = new boolean[list_name.size()];
  46.    ids_check = new int[list_name.size()];
  47.    createTableRows();
  48.  
  49.    }
  50.  
  51.    public void createTableRows()
  52.    {
  53.    for (int i = 0; i < list_name.size(); i++)
  54.    {
  55.    final TableRow table_row = new TableRow(this);
  56.    TextView tv_name = new TextView(this);
  57.    Button btn_check = new Button(this);
  58.    ImageView img_line = new ImageView(this);
  59.  
  60.    table_row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  61.    table_row.setBackgroundColor(color_black);
  62.    table_row.setGravity(Gravity.CENTER_HORIZONTAL);
  63.   // table_row.setFocusable(true);
  64.  
  65.    mRadioGroup = new RadioGroup(this);
  66.  
  67.    // test adding a radio button programmatically
  68.  
  69.    final RadioButton[] mbutton=new RadioButton[7];
  70.    for(int l=0;l<7;l++){
  71.        mbutton[l]=new RadioButton(this);
  72.        mbutton[l].setText("test"+l);
  73.        mRadioGroup.addView(mbutton[l]);
  74.  
  75.    }
  76.  
  77.  
  78.  //  LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
  79.           // RadioGroup.LayoutParams.WRAP_CONTENT,
  80.           // RadioGroup.LayoutParams.WRAP_CONTENT);
  81.   // mRadioGroup.addView(newRadioButton);
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.    tv_name.setText((CharSequence) list_name.get(i));
  89.    tv_name.setTextColor(color_blue);
  90.    tv_name.setTextSize(30);
  91.    tv_name.setTypeface(Typeface.DEFAULT_BOLD);
  92.    tv_name.setWidth(150);
  93.  
  94.    btn_check.setLayoutParams(new LayoutParams(30, 30));
  95.    btn_check.setBackgroundResource(R.drawable.small_checkbox_unchecked);
  96.  
  97.    img_line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 2));
  98.    img_line.setBackgroundResource(R.drawable.separater_line);
  99.  
  100.    table_row.addView(tv_name);
  101.    table_row.addView(btn_check);
  102.    table_row.addView(mRadioGroup);
  103.    table.addView(table_row);
  104.    table.addView(img_line);
  105. //table.addView(mRadioGroup);
  106.  
  107.    mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  108.        public void onCheckedChanged(RadioGroup mRadioGroup, int checkedId) {
  109.             for(int i=0; i<mRadioGroup.getChildCount(); i++) {
  110.                  RadioButton btn = (RadioButton) mRadioGroup.getChildAt(i);
  111.                  int t=table.indexOfChild(table_row);
  112.                  System.out.println(t);
  113.                  if(btn.getId() == checkedId) {
  114.                       String text = btn.getText().toString();
  115.                       // do something with text
  116.                       Log.d(text," event1");
  117.                       return;
  118.                  }
  119.             }
  120.        }
  121.   });
  122.  
  123.  
  124.  
  125.    }
  126.  
  127.    }
  128.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top