开发者

How to Create Dynamic table which row including two cutom check boxes in Android

开发者 https://www.devze.com 2023-03-05 20:31 出处:网络
i want to crate dynamic table which row contain two check boxes(custom check box) and i want to giveto that check boxonCheck or onClick event to that particular check box ..how to create such type of

i want to crate dynamic table which row contain two check boxes(custom check box) and i want to give to that check box onCheck or onClick event to that particular check box ..how to create such type of dynamic layout in Android?? Pl开发者_Go百科ease help me...


Try out this code:

for(int i=0;i<10;i++)
    {
        final TableRow table_row = new TableRow(this);

        final TextView tv_items = new TextView(this);


        tv_items.setText("Textbox"+i);

        final CheckBox chk_box_1 = new CheckBox(this);
        //final CheckBox chk_box_2 = new CheckBox(this);

        table_row.addView(tv_items);
        table_row.addView(chk_box_selected_food);

        table.addView(table_row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

        chk_box_1.setOnCheckedChangeListener(new OnCheckedChangeListener(){ 
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                // TODO Auto-generated method stub
                if(chk_1.isChecked())
                {
                    //your code
                }
                else
                {
                    //your code             
                {

            }

        });

    }

The textview is just for demonstration purpose..you can have another checkbox and can handle the same as the first one

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号