我有电话号码的ArrayList
:使用ArrayList中的指定数字,如何使我的listview中的复选框可见?
ArrayList<String> MatchingContacts;
在我phone_inflate_listview.xml
我已经复选框公开程度设置为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"
/>
如果phoneNumberofContact
属于MatchingContacts
,我想这个电话号码(可以是一个或许多)出现在ListView
的顶部,其他电话号码显示在下方。
我这样做与此代码,在我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);
}
我怎样才能让checkbox
出现肉眼可见的,用于在ListView
顶部的数字,属于MatchingContacts
的人?
,而不是仅仅selectPhoneContacts.add(0, selectContact);
我想:
selectPhoneContacts.add(0, selectContact);
checkBoxforContact.setVisibility(View.VISIBLE);
,但我得到一个错误,说我不得不这样做的UI线程。所以在我的onPostExecute
我说:
//if a phone number is in our array of matching contacts*/
if (MatchingContacts.contains(phoneNumberofContact))
{
checkBoxforContact.setVisibility(View.VISIBLE);
}
adapter.notifyDataSetChanged();
没有错误,应用程序加载罚款,但我所有的复选框仍然是不可见的。有任何想法吗?