mercredi 19 avril 2017

How to put a checkbox associated to each row in table row layout in Android?

I have a table that as a dynamic number of rows. I want to associate a checkbox to each row to be able to choose several rows at the same time to perform actions. My question is how create and associate a checkbox to each row and get the text when I select several checkboxes. This is my code for table and row creation.

 // dara rows
                    final TableRow row = new TableRow(getApplicationContext());
                    row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                            TableLayout.LayoutParams.WRAP_CONTENT));
                    String[] colText={numerochip+"",marcaexploracao,marcaauricular,datanascimento,NIF};
                    for(String text:colText) {
                        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(5, 5, 5, 5);
                        tv.setText(text);
                        row.addView(tv);
                    }




Aucun commentaire:

Enregistrer un commentaire