0

I have an ListView with a SmsArrayAdapter of SMSItem objects.

SmsArrayAdapter.java

public class SmsArrayAdapter extends ArrayAdapter<SMSItem>

I want to update item of ListView. That is why I am taking SMSItem objects in onItemClick method and trying to mark them as read.

SMSItem smsMessageStr = (SMSItem) arrayAdapter.getItem(pos);

if (smsMessageStr.status == false) {
    ((SmsArrayAdapter) arrayAdapter).setRead(pos, smsMessageStr.ID); 

    Toast.makeText(this, "ID is " + smsMessageStr.ID, Toast.LENGTH_LONG).show();

    arrayAdapter.notifyDataSetChanged();
}

The method for marking sms as read as follows which is declared in SmsArrayAdapter.java

public void setRead(int position, String smsMessageId) {
        smsBody.get(position).status = true;
        SMSItem smsItem = smsBody.get(position);
        smsItem.status = true;
        smsBody.set(position, smsItem);
        ContentValues values = new ContentValues();
        values.put("read", true);
        int flag = context.getContentResolver().update(Uri.parse("content://sms/inbox"),
            values, "_id=" + smsMessageId, null);
    Toast.makeText(context, "The result is "+flag, Toast.LENGTH_LONG).show();
    }

The sms is not marking as read. Where is the problem ?

osimer pothe
  • 2,827
  • 14
  • 54
  • 92

0 Answers0