Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6119671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:34:49+00:00 2026-05-23T15:34:49+00:00

I have a listview with a custom array adapter: public class SmsMessageAdapter extends ArrayAdapter<ContactMessage>

  • 0

I have a listview with a custom array adapter:

public class SmsMessageAdapter extends ArrayAdapter<ContactMessage> {

private ArrayList<ContactMessage> items;

public SmsMessageAdapter(Context context, int textViewResourceId, ArrayList<ContactMessage> items) {
    super(context, textViewResourceId, items);
    this.items = items;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if(v == null) {
        LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.message, null);
    }
    ContactMessage c = items.get(position);
    if(c != null) {
        String name = c.getContact();
        if(name.equals("Me")) v.setBackgroundResource(R.drawable.sms_history_outgoing_background_gradient);
        else v.setBackgroundResource(R.drawable.sms_history_incoming_background_gradient);
        TextView contactName = (TextView) v.findViewById(R.id.message_contact_name);
        TextView body = (TextView) v.findViewById(R.id.message_body);
        TextView date = (TextView) v.findViewById(R.id.message_date_time);
        if(contactName != null) {

            contactName.setText(name);
        }
        if(body != null) {
            body.setText(c.getBody());
        }
        if(date != null) {
            date.setText(c.getFormattedTimeString());
        }
    }
    return v;
}
}

I also have a method in my main activity which updates the listview by adding items onto the array list associated with the custom array adapter:

private void displayContactSmsHistory(String phoneNumber) {
    Contact c = new Contact();

    for(Contact contact : mContactsArrayList) {
        if(getOnlyNumerics(phoneNumber).equals(getOnlyNumerics(contact.getPhoneNumber()))) {
            c = contact;
        }
    }

    HashMap<String, Boolean> unreadPositions = mContactsAdapter.getUnreadMap();
    unreadPositions.put(getOnlyNumerics(phoneNumber), false);
    mContactsAdapter.setUnreadMap(unreadPositions);

    HashMap<String, Boolean> selectedPosition = mContactsAdapter.getSelectedMap();
    for(String key : selectedPosition.keySet()) {
        selectedPosition.put(key, false);
    }
    selectedPosition.put(getOnlyNumerics(phoneNumber), true);
    mContactsAdapter.setSelectedMap(selectedPosition);

    String contactName;

    if(c.hasName()) contactName = c.getName();
    else contactName = phoneNumber;

    mConversationArrayAdapter.clear();

    if(!db.isOpen()) db = db.open();
    Cursor smsHistory = db.getSmsForContact(phoneNumber);
    startManagingCursor(smsHistory);
    int bodyIndex = smsHistory.getColumnIndex(DBAdapter.KEY_BODY);
    int dateIndex = smsHistory.getColumnIndex(DBAdapter.KEY_DATE);
    int typeIndex = smsHistory.getColumnIndex(DBAdapter.KEY_TYPE);
    if(smsHistory.moveToFirst()) {
        while(!smsHistory.isAfterLast()) {
            String body = smsHistory.getString(bodyIndex);
            String dateString = smsHistory.getString(dateIndex);
            DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
            Date date;
            try {
                date = df.parse(dateString);
            } catch (ParseException e) {
                Log.e(TAG, "Error parsing date string while displaying contact info:", e);
                date = new Date(0);
            }

            if(smsHistory.getInt(typeIndex) == DBAdapter.RECEIVED) {
                smsHistoryArrayList.add(new ContactMessage(date, contactName, body));
            } else {
                smsHistoryArrayList.add(new ContactMessage(date, null, body));
            }

            smsHistory.moveToNext();
        }
    }
    stopManagingCursor(smsHistory);
    if(db.isOpen()) db.close();

}

The update method can be called from two different places in my code; 1) if the user selects an item from another listview, and 2) if I call the method directly in certain situations. This all works find and dandy, except in the situation where the user presses the back button (which initiates a call to onDestroy()), then returns to the app (causing a new call to onCreate()). If that happens, the listview will only update from one place in my code (if the user selects an item in the other listview). For the other situations where the update method is called, the code is executed but the listview does not update. I’ve run through with the debug tool, watching variables inside the update method and I can’t see any reason why the listview is not updating.

Also note, if the user presses the home button, instead of the back button, and then returns to the app, everything works fine. In this situation onDestroy() and onCreate() are never called, only onStop() and onStart().

If necessary I can post my onCreate() and onDestroy(), however I can say now that there is nothing in those two methods which I believe is causing the error (onCreate() simply loads preferences and sets the layout, and onDestroy() closes the database).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:34:49+00:00Added an answer on May 23, 2026 at 3:34 pm

    I ended up reverting to an earlier SVN commit and rewriting my previous progress. The problem didn’t occur a second time… I still have no idea why it happened in the first place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have list activity with custom array adapter and I can't to get context
I have created a custom ArrayAdapter to display data within ListView items from an
I have a custom ListView adapter which implements an ImageThreadLoader class. Unfortunately, the class
I have a custom ListView adapter which implements an ImageThreadLoader class. Unfortunately the class
I have a listview, with around 200 items, I have implemented a custom ArrayAdapter
I have a ListView with a custom list adapter (that extends BaseAdapter). My list
I have a listview with a custom arrayadapter that handles about 15 strings. The
I have an activity with a ListView which is populated through a custom ArrayAdapter.
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.