我在我的应用程序中有联系人列表视图...我正在使用数组适配器...虽然更新已添加的联系人我需要将复选框visibilty设置为true已经点击的复选框..我知道查看在适配器中将调用列表的每一行...
这是我的适配器代码
class ContactDispAdapter extends ArrayAdapter<UserMO> {
private ArrayList<UserMO> userMOs;
LayoutInflater mInflater;
public ContactDispAdapter(Context context, int textViewResourceId,
ArrayList<UserMO> userMOs) {
super(context, textViewResourceId, userMOs);
this.userMOs = new ArrayList<UserMO>();
this.userMOs.addAll(userMOs);
}
private class ViewHolder {
TextView userNameTxtV;
TextView mobileNumTxtV;
CheckBox cb;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
// Create a new row view
if (convertView == null) {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.contactlist, null);
holder = new ViewHolder();
// Find the child views.
holder.userNameTxtV = (TextView) convertView.findViewById(R.id.text);
holder.mobileNumTxtV = (TextView) convertView.findViewById(R.id.mobile_number);
holder.cb = (CheckBox) convertView.findViewById(R.id.check_box);
// Optimization: Tag the row with it's child views, so we don't have
// to
// call findViewById() later when we reuse the row.
convertView.setTag(holder);
}
// Reuse existing row view
else {
// Because we use a ViewHolder, we avoid having to call
// findViewById().
holder = (ViewHolder) convertView.getTag();
}
holder.cb.setTag(userMOs.get(position));
EventMO eventMO2 = (EventMO) getIntent().getParcelableExtra("eventMO");
if (eventMO2 != null) {
List<EventUserRelationMO> eventUserRelationMOs = eventMO2.getEventUserRelationBOs();
Log.i("relationMO", "MO inside adapter " + eventUserRelationMOs);
for(EventUserRelationMO eventUserRelationMO:eventUserRelationMOs){
int isInvited = eventUserRelationMO.getIsInvited();
if (isInvited == 1) {
holder.cb.performClick();
} else {
Log.i("inside ", "false");
}
}
}
holder.userNameTxtV.setText(userMOs.get(position).getUserName());
holder.mobileNumTxtV.setText(userMOs.get(position).getMobileNumber());
holder.cb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox checkBox = (CheckBox) v;
UserMO userMO = (UserMO) checkBox.getTag();
userMO.setSelected(checkBox.isChecked());
Log.i("is selected", "usermo" + userMO.isSelected());
Log.i("mo", "user" + userMO);
}
});
holder.cb.setChecked(userMOs.get(position).isSelected());
return convertView;
}
}
}
这里我从数据库获取事件用户关系MO列表。从我设置复选框可见性为真基于是邀请属性..
这里我的问题是为联系人的每一行调用get视图,因此每次事件User Relation MOs都会执行...所以我无法正确设置可见性复选框。 .. 对于列表的第一行,我只需要检查eventUserRelationMOs的第一个索引..... 对于第二行列表视图,我需要执行eventUserRelationMOs的第二个索引....仅此而我可以设置复选框visibilty
我不知道该怎么做..请帮我找......