greetings my fellow developers, i am working on a project in which i have a listview consists on 2 textviews and 1 checkbox in each item, my listview is working as i want it to, except for when i programmatically use setSelection(some_index) on the list view all the chechboxes that were check on previous OnItemClickListener calls gets unchecked, i am trying to figure out why this is but so far no luck, i did try to check and change all the check boxes after each scroll with this
for (int i = 0; i < listView.getCount(); i++) {
View mChild = listView.getChildAt(i);
View mChild1 = listView.getAdapter().getView(i, null, null);
TextView name = (TextView) mChild.findViewById(R.id.contact_name);
TextView phone = (TextView) mChild.findViewById(R.id.contact_number);
CheckBox box = (CheckBox) mChild.findViewById(R.id.contact_check);
if(contact.getName().equals(name.getText().toString()) && contact.getPhone().equals(phone.getText().toString()))
box.setChecked(true);
}
both methods (mchild and mchild1) dont work, plus it is taking to much processing time, since my list view will likely be very long,(give or take 500 items) any help regarding this issue, i have been stuck on this for couple of days, but couldn't comeup with any considerable solutions, one thing i dont understand is that why my listview dataset is changing on scroll, any help, is there is any easier and faster way to do this, then itetrating through childs of listview? if no then why my logic of iteration dont work here is my listview items
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/list_view_margin_vertical"
android:layout_marginTop="@dimen/list_view_margin_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/contact_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorBlack"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large" />
<TextView
android:id="@+id/contact_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorGrey"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium" />
</LinearLayout>
<CheckBox
android:id="@+id/contact_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:layout_gravity="center" />
</LinearLayout>
this is my listview itself
<ListView
android:id="@+id/contactsListView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:divider="@color/colorAccent"
android:dividerHeight="1dp"
android:footerDividersEnabled="false" />
Aucun commentaire:
Enregistrer un commentaire