在我的自定義適配器中,我有一個電話號碼的數組列表,checkedContactsAsArrayList
,我從我的php
獲得。在我的Android應用程序,它看起來是這樣的:如何使我的自定義適配器默認選中複選框?
[+12345,+23456,+34567]
我做一個字符串,contactToCheck
,從checkedContactsAsArrayList
每個值,有:
for (int i = 0; i < checkedContactsAsArrayList.size(); i++) {
contactToCheck = checkedContactsAsArrayList.get(i);
}
的contactToCheck
值將始終存在於另一個數組列表,MatchingContactsAsArrayList
。
例如,MatchingContactsAsArrayList
可能是這樣的:
[+12345,+23456,+34567,+45678,+56789,]
一個checkbox
負載在這些電話號碼旁邊我Listview
的所有單元格,但對於contactToCheck
數字我想的複選框被選中/默認選中。
你能告訴我什麼,我需要把我的
if (MatchingContactsAsArrayList.contains(contactToCheck))
{
}
要做到這一點?
這裏是我的getView
代碼:
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
System.out.println("getView number is :" + i + "convertView is : " + convertView);
ViewHolder viewHolder = null;
if (convertView == null) {
//if there is nothing there (if it's null) inflate the view with the layout
LayoutInflater li = (LayoutInflater) _c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.phone_inflate_listview, null);
viewHolder = new ViewHolder();
// So, for example, title is cast to the name id, in phone_inflate_listview,
// phone is cast to the id called no etc
viewHolder.title = (TextView) convertView.findViewById(R.id.name);
viewHolder.phone = (TextView) convertView.findViewById(R.id.no);
viewHolder.invite = (Button) convertView.findViewById(R.id.btnInvite);
viewHolder.check = (CheckBox) convertView.findViewById(R.id.checkBoxContact);
//remember the state of the checkbox
viewHolder.check.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) _c);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
// store the holder with the view
final SelectPhoneContact data = (SelectPhoneContact) arraylist.get(i);
//in the listview for contacts, set the name
viewHolder.title.setText(data.getName());
//in the listview for contacts, set the number
viewHolder.phone.setText(data.getPhone());
////*********************
//for every phone number in the MatchingContactsAsArrayList array list...
for (int number = 0; number < MatchingContactsAsArrayList.size(); number++) {
if (MatchingContactsAsArrayList.contains(contactToCheck))
{
}
}
viewHolder.check.setChecked(data.isSelected());
viewHolder.check.setTag(data);
// Return the completed view to render on screen
return convertView;
}