samedi 16 septembre 2017

With specified numbers from an ArrayList,how do I make the checkbox in my listview visible?

I have an ArrayList of phone numbers:

ArrayList<String> MatchingContacts;

In my phone_inflate_listview.xml I have checkbox visibilty set to invisible:

        <CheckBox
            android:id="@+id/checkBoxContact"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:checked="false"
            android:visibility="invisible"
            android:clickable="true"
 />

If phoneNumberofContact belongs to MatchingContacts, I want this phone number (can be one or many) to appear at the top of the ListView, and the other phone numbers to appear underneath.

I do this with this code, in my AsyncTask doInBackground:

   //if a phone number is in our array of matching contacts*/
            if (MatchingContacts.contains(phoneNumberofContact))

            {
                // insert the contact at the beginning of the listview
                selectPhoneContacts.add(0, selectContact);
            }

            else {
                // insert it at the end (default)
                selectPhoneContacts.add(selectContact);
            }

            selectContact.setName(phoneNameofContact);
            selectContact.setPhone(phoneNumberofContact);
        }

How can I make the checkbox appear visible, for the numbers at the top of the ListView, the ones that belong to MatchingContacts?

Instead of just selectPhoneContacts.add(0, selectContact); I tried:

        selectPhoneContacts.add(0, selectContact);
        checkBoxforContact.setVisibility(View.VISIBLE);

but I got an error, saying I had to do this in the UI thread. So in my onPostExecute I added:

    //if a phone number is in our array of matching contacts*/
    if (MatchingContacts.contains(phoneNumberofContact))

    {
        checkBoxforContact.setVisibility(View.VISIBLE);
    }

    adapter.notifyDataSetChanged();

No errors, the app loads fine, but all my checkboxes are still not visible. Any ideas?




Aucun commentaire:

Enregistrer un commentaire