问题描述
我从我的数据库中获取数据使用
I get data from my DB using
cursor = db.query("WebLeadMaster", select, "condition1="+conditionVal1+
" and condition2="+ConditionVal2,null, null, null, "RegistrationTime DESC");
我在游标中取得资料。要显示数据,我使用以下代码:
I am getting the data in my cursor alright. To display the data, i use the following code:
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
R.layout.resultleadlookup, cursor, columns, to);
mAdapter.notifyDataSetChanged();
lstResult.setAdapter(mAdapter);
所以,我不能修改游标的内容。排序查询的条件为RegistrationTime,这是一种 字符串数据类型。如下图所示,它不是一个正确的排序格式。 (不根据日期时间)。
So, I cannot modify the contents of the cursor. The sort query has condition "RegistrationTime" which is a String data type. As you can see in the image below, it is not in a proper sorted format. (not according to date-time).
我应该在我的代码中做什么更改,以便它可以根据日期时间正确排序?
What changes should i make in my code so that it would sort properly according to date-time?
如果我改变我的DB查询,看起来像
If i alter my DB query, to look like
cursor = db.query("WebLeadMaster", select, "condition1="+conditionVal1+
" and condition2="+ConditionVal2,null, null, null, null);
它给出一个升序。
推荐答案
好吧,我改变了我的表结构。我添加了另一个字段_id。将属性设置为 AUTO INCREMENT ,并将其按 _id 字段排序。
Well, i changed my table structure. I added another field "_id" to it. Set the property as AUTO INCREMENT to it, and sorted the list with respect to _id field.
这篇关于排序DB数据并在列表视图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!