</pre>StickyListHeadersListView框架的用法1.集合里面的对象,不同的类型设置不同的标识(int型)2.适配器要继承 BaseAdapter实现StickyListHeadersAdapter extends BaseAdapter implements StickyListHeadersAdapter3.适配器中多实现两个方法(用来自动添加分栏)<span style="white-space:pre"></span>//分栏显示的条目view(根据当前对象的类型返回不同的内容)<span style="white-space:pre"></span>View getHeaderView(int position, View convertView,ViewGroup parent)<span style="white-space:pre"></span>//显示分栏(分栏下的条目)的类型<p><span style="font-size:18px"><span style="white-space:pre"></span>long getHeaderId(int position) 返回当前对象的标识</span></p><p><span style="font-size:18px">实现效果如图</span></p><p><span style="font-size:18px"><img src="https://img-blog.csdn.net/20160629001148477?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" align="left" alt="" /></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"></span></p><p><span style="font-size:18px"><strong>集合中对象的代码</strong></span></p><p><span style="font-size:18px">public class RunProgressInfo {<span style="white-space:pre"></span>private String packageName;<span style="white-space:pre"></span>private String lable;<span style="white-space:pre"></span>private String size;<span style="white-space:pre"></span>private Drawable con;<span style="white-space:pre"></span>private boolean isUseApp;<span style="white-space:pre"></span>private boolean ischeacked;<span style="white-space:pre"></span>private int lvtype;</span></p><p><span style="font-size:18px">}</span></p><p><span style="font-size:18px"><strong>适配器中的代码</strong></span></p><p><span style="font-size:18px"><strong></strong></span></p><pre name="code" class="java" style="font-size: 18px;">class ProgressAdapter extends BaseAdapter implements
StickyListHeadersAdapter {
private List<RunProgressInfo> progresses;
public List<RunProgressInfo> getProgresses() {
return progresses;
}
public void setProgresses(List<RunProgressInfo> progresses) {
this.progresses = progresses;
}
public ProgressAdapter(List<RunProgressInfo> progresses) {
this.progresses = progresses;
}
@Override
public int getCount() {
Boolean showsys = SpUtils.getBoolean(RunProgressActivity.this,
SpConstants.NAME_PROGRESS_SET,
SpConstants.SHOW_SYS_PROGRESS);
return showsys ? progresses.size() : useProgresses.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
HolderView hv = null;
if (convertView == null) {
hv = new HolderView();
convertView = View.inflate(RunProgressActivity.this,
R.layout.progress_item, null);
hv.iv_con = (ImageView) convertView
.findViewById(R.id.iv_progress);
hv.tv_progress_lable = (TextView) convertView
.findViewById(R.id.tv_progress_lable);
hv.tv_progress_size = (TextView) convertView
.findViewById(R.id.tv_progress_size);
hv.cb_progress = (CheckBox) convertView
.findViewById(R.id.cb_progress);
convertView.setTag(hv);
} else {
hv = (HolderView) convertView.getTag();
}
final RunProgressInfo pf = progresses.get(position);
Log.i("test", hv + "hv");
hv.iv_con.setImageDrawable(pf.getCon());
hv.tv_progress_lable.setText(pf.getLable());
hv.tv_progress_size.setText(pf.getSize());
hv.cb_progress.setChecked(pf.isIscheacked());
hv.cb_progress.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
cb.setChecked(!pf.isIscheacked());
pf.setIscheacked(cb.isChecked());
}
});
return convertView;
}
@Override
public View getHeaderView(int position, View convertView,
ViewGroup parent) {
TextView tv =null;
if (convertView == null) {
tv = new TextView(RunProgressActivity.this);
tv.setBackgroundResource(R.color.bule_light);
tv.setTextSize(18);
tv.setTextColor(R.color.write);
convertView =tv ;
}else {
tv = (TextView) convertView;
}
tv.setText(getHeaderId(position) == 0 ? "用户应用:"
+ useProgresses.size() + "个" : "系统应用:"
+ sysProgresses.size() + "个");
return convertView;
}
@Override
public long getHeaderId(int position) {
return progresses.get(position).getLvtype();
}
}
static class HolderView {
private ImageView iv_con;
private TextView tv_progress_lable;
private TextView tv_progress_size;
private CheckBox cb_progress;
}