How to create table layout dynamically inside thread

Deadly 提交于 2019-12-02 04:29:00

问题


I am creating an android app consists of a custom alert dialog.In that dialog i want to create a table layout dynamically with 4 rows and 5 columns. I want to made this with in thread can any one tell me how to create table layout dynamically inside thread This is what i had done but it was showing only dialog name but not the table layout inside thread EDITED:

progresDialog = new Dialog(getActivity());
                progresDialog.setContentView(R.layout.progressdialog);
                progresDialog.setTitle("MANUAL MODE : TESTING ");
                testing_after_fuse_cnc = new Thread(new Runnable() {

                    @Override
                    public void run() {
                    update_handler.post(new Runnable() {

                        @Override
                        public void run() {
                            table_dialog = new TableLayout(getActivity());
                            table_dialog.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
                            table_dialog.setBackgroundColor(Color.parseColor("#FFFFFF"));
                            for(i=1;i<3;i++){
                                tablerow_dialog = new TableRow(getActivity());
                                tablerow_dialog.setLayoutParams(new LayoutParams(android.widget.TableRow.LayoutParams.WRAP_CONTENT,android.widget.TableRow.LayoutParams.WRAP_CONTENT));
                                for(j=1;j<4;j++){
                                    TextView t_v_dialog = new TextView(getActivity());
                                    t_v_dialog.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
                                    t_v_dialog.setBackgroundResource(R.drawable.cell_shape);
                                    t_v_dialog.setPadding(5,5,5, 5);
                                    tablerow_dialog.addView(t_v_dialog);

                                }

                                table_dialog.addView(tablerow_dialog);
                            }
                        }
                    });

                    }
                });
                testing_after_fuse_cnc.start();
                progresDialog.show();

回答1:


The lines

    table_row.addView(t_v_dialog);
} 
table_dialog.addView(table_row); 

should be

    tablerow_dialog.addView(t_v_dialog);
}
table_dialog.addView(tablerow_dialog); 

Don't forget to add table_dialog to your layout container.



来源:https://stackoverflow.com/questions/31140323/how-to-create-table-layout-dynamically-inside-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!