Android 如何将来自发件人的所有短信合并到ListView中的一条短信中,就像在默认的短信应用程序中一样?

Android 如何将来自发件人的所有短信合并到ListView中的一条短信中,就像在默认的短信应用程序中一样?,android,android-layout,android-widget,Android,Android Layout,Android Widget,我有一个显示所有传入短信的列表视图。我想做的是按号码合并所有短信,只显示此发件人收到的短信号码,就像在默认短信应用程序的主窗口中一样 我使用一个列表活动,它使用一个游标适配器来获取如下所示的所有消息: public class MessageList extends ListActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState)

我有一个显示所有传入短信的列表视图。我想做的是按号码合并所有短信,只显示此发件人收到的短信号码,就像在默认短信应用程序的主窗口中一样

我使用一个列表活动,它使用一个游标适配器来获取如下所示的所有消息:

public class MessageList extends ListActivity {

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        inboxcursor = getContentResolver().query(Uri.parse("content://sms/inbox"),new String [] {"person","address","body","date","_id","read", "status", "type", "reply_path_present", "subject","thread_id"} , null, null,"date DESC");
        smsadapter = new MessageListAdapter(this,inboxcursor);  
        getListView().setAdapter(smsadapter);
}

public class MessageListAdapter extends CursorAdapter {

        Context mcontext;
        LayoutInflater inflater;

        public MessageListAdapter(Context context, Cursor cursor) {
            super(context, cursor, true);

            inflater = LayoutInflater.from(context);
            mcontext = context;

        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {

             String number = cursor.getString(cursor.getColumnIndex("address"));
             TextView numbertext = (TextView) view.findViewById(R.id.number);
             numbertext.setText(number);

             String message = cursor.getString(cursor.getColumnIndex("body"));
             TextView messagetext = (TextView) view.findViewById(R.id.message);
             messagetext.setText(message);

        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {

            View view = inflater.inflate(R.layout.listitems, null);

            return view;
            }

        }

在活动中,制作一个
ArrayList
,它将保存要显示的数据。String是发件人的sms号码,int是计数。 然后查询传入消息:

cursor = getContentResolver().query(<sms table, assuming all are incoming. if not, you need to filter it on your where clause>, new String[] {sender column name}, null, null, null};

while(cursor.moveToNext()) {
  String sender = cursor.getString(cursor.getColumnName(<sender column name>));
  // check if the sender string exists in your arraylist. if not, create a new entry and set count to 1. else, get the position of the existing number and increment count by one.
};
cursor=getContentResolver().query(,新字符串[]{sender column name},null,null,null};
while(cursor.moveToNext()){
String sender=cursor.getString(cursor.getColumnName());
//检查您的arraylist中是否存在发件人字符串。如果不存在,请创建一个新条目并将count设置为1。否则,请获取现有数字的位置,并按1递增count。
};

然后将其馈送到ListAdapter或ArrayAdapter。CursorAdapter不会将其剪切。

是否有办法将Filterable实现到我的CursorAdapter?Filterable仅过滤适配器中的项目。它无法以任何方式转换列表。哦,好的。在我使用CursorAdapter之前,我使用ArrayAdapter接收消息。问题是ArrayAdapter和arraylist的缺点是加载速度非常慢,ui线程等待(大约10秒)在它获取所有信息之前,当我切换到asynctask时,情况是一样的,ui线程不会停止,ui显示正常且快速,但是消息会像以前一样在10秒左右的时间内加载。因此没有任何变化。更准确地说,我的列表左侧包含联系人的图片,右侧包含联系人姓名和号码,以及在名称和数字日期和smsso下,当您收到大量消息时,所有这些都会占用大量时间。请您在说明中更精确一些,给我可以键入的准确代码,以便完成所有操作。我无法管理arraylist是否包含数字,并增加计数。更多的帮助将非常宝贵。如何我的arrayadapter应该看看吗?谢谢你的帮助。你能分享你的工作代码吗?