大佬教程收集整理的这篇文章主要介绍了android – 动态创建每月包含标题行的列表视图,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
以下是我需要的要求:
> listview的数据需要来自sqlite数据库(请参阅下面的表格布局代码)
>数据应按月分组(月/年奖励积分)
>标题行应包含该月份数据库中记录的项目数
>必须与API 8兼容
>需要能够单击某个项目以打开包含当天执行的移动的对话框(我已经知道如何创建列表后如何执行此操作)
看看jeff Snarkey的seperatedlistadapter:http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/我能够提出以下内容:
datasource = new smashDatasource(this); datasource.open(); BJJHistory = (ListView) findViewById(R.id.ListHistory); // create our list and custom adapter adapter = new Separatedlistadapter(this); HistoryBJJ = datasource.getBJJHistory(); // THE DESIRED columNS TO BE BOUND final String[] columns = new String[] { sqliteHelper.DATE }; // THE XML DEFINED VIEWS WHICH THE DATA WILL BE BOUND TO final int[] to = new int[] { R.id.list_item_title }; if (HistoryBJJ != null) { adapter.addSection("October",new SimplecursorAdapter(this,R.layout.list_item,HistoryBJJ,columns,to)); } BJJHistory.setAdapter(adapter);
public cursor getBJJHistory() { final String[] columns = { sqliteHelper.COLUMN_ID,sqliteHelper.DATE }; final cursor History; History = database.query(sqliteHelper.TABLE_BJJ,null,sqliteHelper.DATE + " DESC"); return History; }
这导致以下结果:
一开始这很好,但是我遇到了两个问题:
>如何用月份动态填充“标题”值?我已经考虑过使用游标用月份列表填充数组(在用SimpleDateFormat格式化之后),然后执行For Each循环遍历每个循环,将月份传递回游标方法以提取所有条目具有该月份的日期时间值.
>如何将结果显示为当天的条目数?理想情况下,我喜欢这样的事情:
#2的答案有点简单,只需在listview行布局中放置两个textview,更复杂的是如何对每天的数据库中的所有行进行分组,或者至少对每天进行计数并使用该计数显示在列表中.
对于第一个,回到这里的示例代码:http://code.google.com/p/android-section-list/,而不是提供的示例数组,我想我可以更改以下内容:
SectionListItem[] exampleArray = { // Comment to prevent re-format new SectionListItem("Test 1 - A","A"),// new SectionListItem("Test 2 - A",// new SectionListItem("Test 3 - A",// new SectionListItem("Test 4 - A",// new SectionListItem("Test 5 - A",// new SectionListItem("Test 6 - B","B"),// new SectionListItem("Test 7 - B",// new SectionListItem("Test 8 - B",// new SectionListItem("Test 9 - Long","Long section"),// new SectionListItem("Test 10 - Long",// new SectionListItem("Test 11 - Long",// new SectionListItem("Test 12 - Long",// new SectionListItem("Test 13 - Long",// new SectionListItem("Test 14 - A again",// new SectionListItem("Test 15 - A again",// new SectionListItem("Test 16 - A again",// new SectionListItem("Test 17 - B again",// new SectionListItem("Test 18 - B again",// new SectionListItem("Test 19 - B again",// new SectionListItem("Test 20 - B again",// new SectionListItem("Test 21 - B again",// new SectionListItem("Test 22 - B again",// new SectionListItem("Test 23 - C","C"),// new SectionListItem("Test 24 - C",// new SectionListItem("Test 25 - C",// new SectionListItem("Test 26 - C",//
并将其替换为游标或白天不需要的数据,而不是“A”,“B”,“C”,将其替换为月份名称.
这对我来说非常困惑,因为我还在学习,我已经完成了这个应用程序的几乎所有部分,我只是无法弄清楚如何将数据划分为一个列表
作为参考,这是一个“CardioTrainer”的截图,这是一个具有自定义分区列表的锻炼应用程序,但基本上是我试图复制的,至少在功能上.
这个来自的表看起来像这样:
其次使用合并适配器很简单.
addView(你的剖面视图)
addAdapter(您的特定部分适配器)
这应该让你去:)
希望能帮助到你.
以上是大佬教程为你收集整理的android – 动态创建每月包含标题行的列表视图全部内容,希望文章能够帮你解决android – 动态创建每月包含标题行的列表视图所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。