加入二合一光标列表视图与分隔线 [英] join two cursor listviews in one with separator lines

查看:153
本文介绍了加入二合一光标列表视图与分隔线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要连接两个列表视图中之一,并添加两个空字段beetween所述第一和第二部分的结果。

i need to join two listviews in one and add two blank fields beetween the results of the first and the second part.

由于我使用的是的光标我已经使用选择... UNION SELECT ...,并加入了结果,但是我无法插入空行的在中间的,因为我给他们的负面的ID,以便在以后识别他们,他们得到的顶部或在列表的底部,但我需要他们以某种方式在中间beetween两组数据。

Since i am using a cursor i have used "select ... union select ..." and joined the results, however i am having trouble inserting the empty rows in the middle since i give them negative ids in order to identify them later and they get at the top or at the bottom of the list, but i need them somehow in the middle beetween the two data sets.

此外,我需要知道哪些是空字段,这样我可以禁用它们,我自己也尝试MergeCursor但我重复的结果。

Also i need to know which are the empty fields so that i can disable them, i have also tried MergeCursor but it duplicates my results.

推荐答案

如果您使用CommonWare的 MergeAdapter 应该是很简单的实现你想要的结果。

If you use CommonWare's MergeAdapter it should be quite simple to achieve your desired result.

这将需要多个列表(并且还可以增加个人的意见为好,这样你的空行可以插入),并把它们放在一起列表中的使用。

It will take multiple lists (and you can add individual views as well, so your empty lines can be inserted) and put them all together to be used in your list.

下面是一个链接一个答案,我最近给给人如何使用MergeAdapter更深入的解释。

Here is a link to an answer I recently gave giving a more in depth explanation of how to use the MergeAdapter.

修改

这听起来像使用UNION您的查询,JOIN是给你复制光标结果。试戴分成两个独立的光标。然后创建两个列表适配器,和你的两个空的观点,并补充说,所有进入mergeadapter并将其设置为你的列表视图。

It sounds like your query with the UNION and JOIN is giving you duplicate results in the cursor. Try separating them into two separate cursors. Then create two list adapters, and your two empty views, and add that all into the mergeadapter and set it to your listview.

lv = (ListView) v.findViewById(android.R.id.mergelist);

Cursor c1 = db.fetchCursor1();
String[] from1 = new String[] { DB.ITEM_1 };
int[] to1 = new int[] { R.id.ListItem1 };
SimpleCursorAdapter ca1 = new SimpleCursorAdapter(getActivity(),
    R.layout.your_layout, c1, from1, to1);

Cursor c2 = db.fetchCursor2();
String[] from2 = new String[] { DB.ITEM_1 };
int[] to2 = new int[] { R.id.ListItem1 };
SimpleCursorAdapter ca2 = new SimpleCursorAdapter(getActivity(),
    R.layout.your_layout, c2, from2, to2);

View Blank1 = getLayoutInflater.inflate(R.layout.blank);
View Blank2 = getLayoutInflater.inflate(R.layout.blank);

myMergeAdapter = new MergeAdapter();
myMergeAdapter.addAdapter(ca1);
myMergeAdapter.addView(Blank1);
myMergeAdapter.addView(Blank2);
myMergeAdapter.addAdapter(ca2);

lv.setAdapter(myMergeAdapter);

这篇关于加入二合一光标列表视图与分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆