android 如何遍历Cursor

private void showItems() {

        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        String col[] = { TITLE, BODY };
        Cursor cur = db.query(TABLE_NAME, col, null, null, null, null, null);
        int title = cur.getColumnIndex(TITLE);
        int body = cur.getColumnIndex(BODY);

        for(cur.moveToFirst();!cur.isAfterLast();cur.moveToNext())
        {
        String name = cur.getString(title);
        String phoneNumber = cur.getString(body);

        sb.append(name+" "+phoneNumber+"\n");
        Log.i("title", name);
        Log.i("body",phoneNumber);
        }
        setNotification();
       
        Integer num = cur.getCount();
        setTitle(Integer.toString(num) + " 条记录");
    }

 

 

public void setNotification()
    {
        NotificationManager nmanager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.icon, "数据库查询结果", System.currentTimeMillis());
        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this,ActivityMain.class), 0);
       
        notification.setLatestEventInfo(this, "查询结果" , sb.toString(), pi);
        nmanager.notify(1, notification);
    }

你可能感兴趣的:(android)