2

I have listview with custom adapter. Every element of this listview has checkbox. Standart function .isChecked() does not work.

someActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    btnShare.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            List<Boolean> listCheck;
            listCheck = new ArrayList<Boolean>();

            for (int i = 0; i < CA_main_trx.editModelArrayList.size(); i++){
                Boolean stat = CA_main_trx.editModelArrayList.get(i).getCheckShare();
                String nilaiPcs = CA_main_trx.editModelArrayList.get(i).getTextView_main_trx2();
                Log.d(TAG, "onClick: --a" + nilaiPcs);
                Log.d(TAG, "onClick: --a" + stat);
            }
        }
    });

CustomeAdapter

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        final String TAG = "CA_Main_Trx : ";
...
        holder.checkShare.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    String id = editModelArrayList.get(position).getTextView_main_trx0();
                    Log.d(TAG, "onCheckedChanged: True"+id);
                }
                else
                    Log.d(TAG, "onCheckedChanged: False");
            }

        });
...

model

package com.m.t;

public class EM_main_trx {

    private boolean checkShare;

    public Boolean getCheckShare() {return checkShare;}

    public void setCheckShare(Boolean checkShare) {
        this.checkShare = checkShare;
    }
}

When checked in custome Adapter i get the checked status. But when i get the data using button in my mainactivity i got stuck. just got null.

Some my reference :

1 Answer 1

2

Just update part of custome adapter to this :

@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
     editModelArrayList.get(position).setCheckShare(b);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.