Reputation: 53
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 :
Upvotes: 2
Views: 153
Reputation: 384
Just update part of custome adapter to this :
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
editModelArrayList.get(position).setCheckShare(b);
}
Upvotes: 2