2

I have a tablelayout, and I add a list item like this with button to change data3 (int type) in the table. It has changed correctly in database but the table not auto update the value of data3 right away to display. Please help me with this problem.

        for (final MonOrder list: Global.listOrder)
    {
        tr = new TableRow(this);
        data1 = new TextView(this);
        data2 = new TextView(this);
        data3 = new TextView(this);
        data4 = new TextView(this);
        data5 = new ImageView(this);
        data6 = new ImageView(this);

        data1.setText(list.getMa_thucdon()+"");
        data2.setText(list.getTen_thucdon());
        data3.setText(list.getSo_luong() + "");
        data4.setText(fm(list.getGia() * list.getSo_luong()) + " VNĐ");
        data5.setImageResource(R.drawable.ic_actioncong);
        data6.setImageResource(R.drawable.ic_tru);

        tr.addView(data1);
        tr.addView(data2);
        tr.addView(data3);
        tr.addView(data4);
        tr.addView(data5);
        tr.addView(data6);
        tblOrder.addView(tr);

        data5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplication(), "Testing..", Toast.LENGTH_SHORT).show();
                list.setSo_luong(list.getSo_luong() + 1);

            }
        });
        data6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplication(), "Testing..", Toast.LENGTH_SHORT).show();
                if (list.getSo_luong() > 1) {
                    list.setSo_luong(list.getSo_luong() - 1);
                } else {
                    Global.listOrder.remove(list);
                }
            }
        });
        tblOrder.invalidate();
        tblOrder.refreshDrawableState();

 }
Trí Dũng
  • 41
  • 1
  • Accordting to [this reply](http://stackoverflow.com/a/10381206/515948) you'd need to invalidate with a handler. Alternatively, if possible, you could use e.g. `ListView`. – Laur Ivan Nov 26 '15 at 13:52

0 Answers0