使用StickyListHeaders时出现奇怪的错误

时间:2016-03-10 00:06:53

标签: java android listview

我在我的应用程序中使用se.emilsjolander:stickylistheaders:2.7.0并得到一个奇怪的结果。当我向下滚动列表视图时,会显示某个标题"出勤"。但是,当我将标题传递到下一个#34; Cafeteria"显示,直到该标题被删除。在自助餐厅过世后,自助餐厅突然变回了我眼前的出席。实际上应该有两个不同的标题,包括自助餐厅和出席。这是我用于列表视图适配器的代码:

 List<StaffItem> itemList;

 @Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
    HeaderViewHolder holder;
    if (convertView == null) {
        holder = new HeaderViewHolder();
        convertView = View.inflate(context, R.layout.stafflistviewtextheader, null);
        holder.itemTitle = (TextView) convertView.findViewById(R.id.text);
        if (face1!=null)
            holder.itemTitle.setTypeface(face1);
        convertView.setTag(holder);

    } else {
        holder = (HeaderViewHolder) convertView.getTag();
    }
 //set header text as first char in name
    headerText = itemList.get(position).getStafDepartment();
    holder.itemTitle.setText(headerText);
    return convertView;
}

    @Override
public long getHeaderId(int i) {
    if (itemList.get(i).getStafDepartment().length()>4){
    return itemList.get(i).getStafDepartment().charAt(4);}
    else if (itemList.get(i).getStafDepartment().length()>3){
        return itemList.get(i).getStafDepartment().charAt(3);}
    else if (itemList.get(i).getStafDepartment().length()>2){
        return itemList.get(i).getStafDepartment().charAt(2);}
    else if (itemList.get(i).getStafDepartment().length()>1){
        return itemList.get(i).getStafDepartment().charAt(1);}
    else if (itemList.get(i).getStafDepartment().length()>0){
        return itemList.get(i).getStafDepartment().charAt(0);}
    else{
    return 'a';}
}


class HeaderViewHolder {
    TextView itemTitle;
}

列表项目:

  public class StaffItem{

private final String stafDepartment;
private final String affiliation;
private final String webpage;
private final String email;
private final Boolean department;
private final String name;
public StaffItem(String staffDepartment, String affiliation , String webpage, String email, Boolean department, String name) {
    this.stafDepartment = staffDepartment; this.affiliation= affiliation; this.webpage= webpage;this.email= email; this.department= department;
    this.name= name;
}

public String getStafDepartment() {
    return stafDepartment;
}

public String getAffiliation(){return affiliation;}
public String getWebpage(){return webpage;}
public String getEmail(){return email;}
public Boolean getDepartment(){return department;}
public String getName(){return name;}



}

0 个答案:

没有答案