update dynamic tablelayout in scrollview using a button

418 Views Asked by At

I have created dynamically a LinearLayout and inside a HorizontalScrollView and I have placed insite a TableLayout (my table is too big an I need to scroll). When first created my table has a row as a header and a row for the user to input data. Outside the HorizontalScrollView but inside the LinearLayout I want to add 2 buttons. One for adding a row and one for deleting rows. I setup onclickListener but it did not work. My code is :

LinearLayout linearLayout = new LinearLayout(findViewById(R.id.internal_nodes_layout).getContext());
HorizontalScrollView scrollView1 = new HorizontalScrollView(findViewById(R.id.opaque_scroll_view).getContext());
    TableLayout in_opaque_table = new TableLayout(findViewById(R.id.opaque_table).getContext());
    LinearLayout opaquebuttonsLayout = new LinearLayout(findViewById(R.id.opaque_buttons_layout).getContext());
    TableRow in_opaque_table_HeaderRow = new TableRow(this);
            in_opaque_table_HeaderRow.setLayoutParams(tlparams);
    //.............. code for header...............
    createRowInOpaqueTable(in_opaque_table, in_opaque_table_num_of_rows, tlparams); 
            scrollView1.addView(in_opaque_table);
            opaquebuttonsLayout.addView(addInOpaque);
        opaquebuttonsLayout.addView(removeInOpaque);
linearLayout.addView(scrollView1);
linearLayout.addView(opaquebuttonsLayout);

    //setup buttons and onClickListeners
    Button addInOpaque = new Button(this);
    addInOpaque.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    addInOpaqueRow(view);
                }
            });
            addInOpaque.setText(R.string.add_line);
            addInOpaque.setAllCaps(false);
            Button removeInOpaque = new Button(this);
            removeInOpaque.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    removeInOpaqueRow(view);
                }
            });

   public void addInOpaqueRow(View view) {
    createRowInOpaqueTable(in_opaque_table, in_opaque_table_num_of_rows, tlparams);
    in_opaque_table_num_of_rows++;
}

public void removeInOpaqueRow(View view) {
    if (in_opaque_table_num_of_rows > 0) {
        in_opaque_table.removeViewAt(in_opaque_table_num_of_rows);
        in_opaque_table_num_of_rows--;
    } else {
        Toast.makeText(this, "Δεν υπάρχουν γραμμές στον πίνακα", Toast.LENGTH_SHORT).show();
    }
}

Although it appears the way I want to the add and remove buttons won't work. I get this message: E/libfingersense_wrapper: libfingersense.so was not loaded

but I see that rows count correct when I use add and remove buttons. Any ideas??

0

There are 0 best solutions below