Android:在顶部显示选定的ListView项

Nitesh Kumar

我有ListView一个TextViewCheckBox我正在ListView用电话联系人填充我可以选择一些CheckBoxes并保存更改。现在,当我返回列表时,我想在选中Checkboxes的顶部显示这些行

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的帮帮我。

CodeWarrior

添加在开始时选定的联系人在您的ArrayList mPhoneContacts通过

mPhoneContacts.add(0, object);

并且不要忘记删除同一对象的副本之一,否则它会在您的文件中显示2个条目ListView

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章