【问题标题】:Query multiple colums from a table and display it in viewlist从表中查询多个列并显示在视图列表中
【发布时间】:2013-07-20 08:18:35
【问题描述】:

从我的数据库查询后,我想在列表视图中显示短信发件人地址和正文 我用这种方式保存了我的短信数据

enter ContentValues values = new ContentValues();
values.put("address", sms.getOriginatingAddress().toString() );
values.put("date", mydate);
values.put("address", sms.getOriginatingAddress().toString() );
values.put("date", mydate);
values.put("body", sms.getMessageBody().toString());

db.insert("datatable", null, values);

现在我想检索数据以在列表视图中显示为“senderaddress”和“body”

我正在尝试以下代码

 String[] arrayColumns = new String[]{"address","body"};
        int[] arrayViewIDs = new int[]{R.id.textViewSMSSender,R.id.textViewMessageBody};

检索数据出现问题

 Cursor cursor;
cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);

我怎样才能使它适合下面的代码

  SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.listview_each_item, cursor, arrayColumns, arrayViewIDs);


listViewSMS.setAdapter(adapter);

【问题讨论】:

    标签: android sqlite android-listview


    【解决方案1】:

    尝试使用以下方法获取数据:

    Cursor cursor = db.query("datatable", new String[] {"address", "body"}, 
                    null, null, null, null, null);
    cursor.moveToFirst();
    

    【讨论】:

    • 我的接收器直接收到短信,默认收件箱中没有短信。所有权限都已添加读写...
    • 我没听懂你。您想显示收件箱中的邮件还是显示您自己的数据库中的邮件?
    • 来自我自己的数据库
    • 问题在这里光标光标; cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);此查询必须不同,因为我没有提供者“uri”
    • 但是如果数据保存在您的数据库中,您为什么要从收件箱中获取数据。 uri 将从短信收件箱中获取数据。
    猜你喜欢
    • 2018-07-30
    • 1970-01-01
    • 2013-12-18
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    相关资源
    最近更新 更多