如何在Android ListView中单击增加计数器

时间:2018-12-13 23:48:35

标签: java android

我想在ListView适配器中增加android计数器,但下一个单击行总是失败增加。

counting_update_cycle = actual.getJson().getCycle();
counting_update = counting_update_cycle;
holder.counting.setText(String.valueOf(counting_update_cycle));

//action tambah
holder.btntambahekekusi.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        holder.counting.setText(String.valueOf(counting_update));
        counting_update++;

    }
});

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

counting_update_cycle = actual.getJson().getCycle();
counting_update = counting_update_cycle;
holder.counting.setText(String.valueOf(counting_update_cycle));

//action tambah
holder.btntambahekekusi.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        // added code
        counting_update_cycle = actual.getJson().getCycle();
        counting_update = counting_update_cycle;

        holder.counting.setText(String.valueOf(counting_update));

        // update instance property of object
        actual.getJson().setCycle(counting_update++);
    }
});