Android:如何更新TableLayout中的行

时间:2015-11-26 11:43:47

标签: android android-layout tablelayout auto-update android-tablelayout

我有一个tablelayout,我添加了一个这样的列表项,带有按钮来更改表中的data3(int类型)。它已在数据库中正确更改,但表不会立即自动更新data3的值以显示。请帮我解决这个问题。

        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();

 }

0 个答案:

没有答案