2017-09-16 31 views
0

我有电话号码的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(); 

没有错误,应用程序加载罚款,但我所有的复选框仍然是不可见的。有任何想法吗?

回答

0

selectContact - 可以有一个变量说“isCbVisible”,指示复选框是否启用/禁用。然后,只要doInBackground中的条件满足,就将“isCbVisible”的值设置为true。 在listview方法的getView()中,您需要检查“isCbVisible”的值,然后显示/隐藏复选框。

相关问题