我有ListView
一个TextView
和CheckBox
。我正在ListView
用电话联系人填充。我可以选择一些CheckBoxes
并保存更改。现在,当我返回列表时,我想在选中Checkbox
es的顶部显示这些行。
package com.sample.demo.demolist;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.sample.demo.ContactLogBean;
import com.sample.demo.R;
public class AutoRecordContactListAdapter extends BaseAdapter {
private ArrayList<ContactLogBean> mPhoneContacts;
private Context mContext;
private LayoutInflater mInfalter;
public AutoRecordContactListAdapter(Context context, ArrayList<ContactLogBean> phoneContacts) {
this.mContext = context;
this.mPhoneContacts = phoneContacts;
mInfalter = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mPhoneContacts.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null) {
convertView = mInfalter.inflate(R.layout.auto_record_contacts_list_item, null);
holder = new ViewHolder();
holder.contactName = (TextView) convertView.findViewById(R.id.auto_record_contact_name);
holder.contactCheckBox = (CheckBox) convertView.findViewById(R.id.auto_record_contact_checkbox);
holder.contactCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.contactName.setText(mPhoneContacts.get(position).getmUserName());
if(mPhoneContacts.get(position).getmIsFiltered().equalsIgnoreCase("true")) {
holder.contactCheckBox.setChecked(true);
} else {
holder.contactCheckBox.setChecked(false);
}
return convertView;
}
public class ViewHolder {
TextView contactName;
CheckBox contactCheckBox;
}
}
如何CheckBox
在顶部显示带有选定es的行?帮帮我。
添加在开始时选定的联系人在您的ArrayList
mPhoneContacts通过
mPhoneContacts.add(0, object);
并且不要忘记删除同一对象的副本之一,否则它会在您的文件中显示2个条目ListView
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句