gpt4 book ai didi

android - 使用游标适配器的粘性列表标题

转载 作者:行者123 更新时间:2023-11-29 01:35:41 25 4
gpt4 key购买 nike

需要帮助!

如何在游标适配器中实现粘性列表 header 。

我想要这样的列表

Header: December, 2014
child: day1 3000Kyats
...
child: day30 4000Kyats

Header: January 2015
child: day1 10000Kyats
.....
child: day30 4000Kyats

Header: Feburay 2015
child: day1 10000Kyats
.....
child: day28 4000Kyats

查询

SELECT SUM(KeyAmount), DAY(KeyDate), MONTHNAME(MONTH(KeyDate)), YEAR(KeyDate)
FROM tbl
GROUP BY DAY(KeyDate), MONTH(KeyDate), YEAR(KeyDate)
ORDER BY YEAR(KeyDate), MONTH(KeyDate), DAY(KeyDate)

查询结果

Amount Day Month Year

20 29 December 2014
44 30 December 2014
25 1 January 2015

目的是用标题显示每日收入总和。在一个标题下,将列出该月的天数。使用基本适配器很容易,但我担心它会很慢。我如何使用游标适配器来做到这一点?有办法吗?

谢谢

最佳答案

如果游标是按字母排序的,则需要使用cursor.moveToPisition(i);:

public class MyAdapter extends CursorAdapter implements StickListHeadersAdapter{
public long getHeaderId(int i){
mCursor.moveToPosition(i);
int j = mCursor.getColumnIndex("Column_of_name");
String name = mCursor.getString(j);
return name.charAt(0);
}

public View getHeaderView(int i, View convertView, ViewGroup viewGroup){
HeaderViewHolder holder;
if (convertView != null){
holder = (HeaderViewHolder) convertView.getTag();
}
else{
convertView = LayoutInflater.from(mContext).inflate(R.layout.list_header_tree, viewGroup, false);
holder = new HeaderViewHolder(convertView);
convertView.setTag(holder);
}

mCursor.moveToPosition(i);
int j = mCursor.getColumnIndex("Column_of_name");
String name = mCursor.getString(j);
String headerText = "" + name.charAt(0);
holder.tvHeader.setText(headerText);
return convertView;
}

//Using butterknife so HeaderViewHolder:
static class HeaderViewHolder {
@InjectView(R.id.tvHeader) TextView tvHeader;

public HeaderViewHolder(View view) {
ButterKnife.inject(this, view);
}
}
}

关于android - 使用游标适配器的粘性列表标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28272839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com