如何在CursorAdapter中使用2个游标?
我想显示给定电话号码的收件箱和发送的消息。我的适配器是这样的:
public class MessageListAdapter extends CursorAdapter {
LayoutInflater inflater;
public MessageListAdapter(Context context, Cursor inbox) {
super(context, inbox);
inflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView messagetext= (TextView) view.findViewById(R.id.message);
messagetext.setText(inbox.getString(0));
TextView date= (TextView) view.findViewById(R.id.message);
date.setText(inbox.getString(1));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup group) {
View view = inflater.inflate(R.layout.inboxlistitems, null);
return view;
}
}
我希望它按日期排序,就像默认消息应用程序中的对话一样。我该怎么做呢?是否可能,或者我应该使用 ArrayAdapter?
I want to display inbox and sent messages for a given phone number. My adapter is like this :
public class MessageListAdapter extends CursorAdapter {
LayoutInflater inflater;
public MessageListAdapter(Context context, Cursor inbox) {
super(context, inbox);
inflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView messagetext= (TextView) view.findViewById(R.id.message);
messagetext.setText(inbox.getString(0));
TextView date= (TextView) view.findViewById(R.id.message);
date.setText(inbox.getString(1));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup group) {
View view = inflater.inflate(R.layout.inboxlistitems, null);
return view;
}
}
I want it to be sorted by date, like a conversation in default messaging app. How can I do it? is it possible, or should I use instead an ArrayAdapter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以使用 mergeCursor:
http://developer.android.com/参考/android/database/MergeCursor.html
你可以在这里找到一个例子:
ListView 使用两个光标适配器?
I think you could use a mergeCursor:
http://developer.android.com/reference/android/database/MergeCursor.html
You can find an example here:
ListView using two cursoradapters?