Note that there are some explanatory texts on larger screens.

plurals
  1. POListView Delete Button on Checkbox checked
    primarykey
    data
    text
    <p>I need the following flow to work out: Once I tap to check any of my listview items checkboxes, a Delete Button should appear. If I uncheck all checkboxes, the Delete Button should disappear. My problem is that once make a setOnCheckedChangeListener to make Delete visible/gone, on my CheckBox View, it will automatically uncheck itself, after I scroll the listview, and it is not visible any more on my screen (`cause of recycling the views).</p> <p>Any ideas on how to get a total_number_of_checkboxes_checked variable, that would increase or decrease with 1. (I repeat, counting all checkboxes checked, not only the visible on screen ones).</p> <p>EDIT: added code</p> <hr> <h2>Adapter</h2> <hr> <pre><code>public class AdminNotesAdapter extends BaseAdapter { private ArrayList&lt;AdminNoteShortenHolder&gt; mNotesList = new ArrayList&lt;AdminNoteShortenHolder&gt;(); private AdminNoteShortenHolder mNoteHolder = new AdminNoteShortenHolder(); private ViewHolder holder = null; private Activity activity; public AdminNotesAdapter(ArrayList&lt;AdminNoteShortenHolder&gt; array, Activity activity) { this.activity = activity; this.mNotesList = array; } @Override public int getCount() { return mNotesList.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { mNoteHolder = mNotesList.get(position); if (convertView == null) { convertView = activity.getLayoutInflater().inflate( R.layout.row_adminnotes, null); holder = new ViewHolder(convertView); holder.cb_row_adminNotesCheck .setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { int getPosition = (Integer) buttonView.getTag(); mNotesList.get(getPosition).setSelected(isChecked); } }); convertView.setTag(holder); convertView.setTag(R.id.cb_row_adminnotesCheck, holder.cb_row_adminNotesCheck); } else { holder = (ViewHolder) convertView.getTag(); } holder.img_row_adminnotesNew .setVisibility(0 == mNoteHolder.note_read ? View.VISIBLE : View.GONE); holder.txt_row_adminnotesNoteSubject.setText(mNoteHolder.note_subject); holder.txt_row_adminnotesNoteUser.setText("from " + mNoteHolder.note_from_user + " | " + mNoteHolder.note_time); holder.txt_row_adminnotesNotePreview.setText(mNoteHolder.note_content); holder.cb_row_adminNotesCheck.setTag(position); holder.cb_row_adminNotesCheck.setChecked(mNotesList.get(position) .isSelected()); return convertView; } static class ViewHolder { public ImageView img_row_adminnotesNew; public TextView txt_row_adminnotesNoteSubject; public TextView txt_row_adminnotesNoteUser; public TextView txt_row_adminnotesNotePreview; public CheckBox cb_row_adminNotesCheck; public ViewHolder(View convertView) { img_row_adminnotesNew = (ImageView) convertView .findViewById(R.id.img_row_adminnotesNew); txt_row_adminnotesNoteSubject = (TextView) convertView .findViewById(R.id.txt_row_adminnotesNoteSubject); txt_row_adminnotesNoteUser = (TextView) convertView .findViewById(R.id.txt_row_adminnotesNoteUser); txt_row_adminnotesNotePreview = (TextView) convertView .findViewById(R.id.txt_row_adminnotesNotePreview); cb_row_adminNotesCheck = (CheckBox) convertView .findViewById(R.id.cb_row_adminnotesCheck); } } } </code></pre> <h2>AdminNoteShortenHolder (Model class)</h2> <pre><code>public class AdminNoteShortenHolder extends BaseHolder { public int note_id; public String note_from_user; public String note_subject; public String note_content; public String note_time; public int note_read; private boolean selected; @Override public void parse(JSONObject jsonObject) { note_id = jsonObject.optInt("note_id", -1); note_from_user = jsonObject.optString("note_from_user"); note_subject = jsonObject.optString("note_subject"); note_content = jsonObject.optString("note_content"); note_time = jsonObject.optString("note_time"); note_read = jsonObject.optInt("note_read", -1); } public boolean isSelected() { return selected; } public void setSelected(boolean selected) { this.selected = selected; } } </code></pre> <p>This is what I've done so far, so I managed to maintain the CheckBoxes status over the scrolling of the ListView with the help of setTag / getTag. Problem is, I have a Delete Button in my Activity that should be visible/gone whenever there is at least one Checkboxes checked or none.. Let me know if you have any ideas.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload