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 8266021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:00:37+00:00 2026-06-08T05:00:37+00:00

I have a custom Cursor Adapter that is based off of the MMS and

  • 0

I have a custom Cursor Adapter that is based off of the MMS and SMS database in android. code looks like this as follows:

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

    Message m = Message.getMessage(context, cursor); // gets message from cursor
    int t = m.getType(); // this gets the type of message it is .. 2 = recv, 1 = sent

    switch(t){
    case Message.MMS_IN: // 128
        return mInflater.inflate(R.layout.messagelist_item_recv, parent, false);
    case Message.MMS_OUT: // 132
        return mInflater.inflate(R.layout.messagelist_item_sent, parent, false);
    case Message.SMS_IN: // 2
        return mInflater.inflate(R.layout.messagelist_item_recv, parent, false);
    case Message.SMS_OUT: // 1
        return mInflater.inflate(R.layout.messagelist_item_sent, parent, false);
    default:
        return null;
    }
}

The R.layout.messagelist_item_sent is for sent messages and the R.layout.messagelist_item_recv is for received messages.
But looking at my messages, the rows that are first shown when the listview are shown correctly, but when I go up the listview to new views, the layouts are mixed up. The recv layout is where the sent layout is supposed to be and vice versa. Any one know why this kind of problem would be occuring?

* EDIT **

@Override
public int getItemViewType(int position) {
     // move the cursor to the position
Cursor c = (Cursor)getItem(position);
Message m = Message.getMessage(context, c);

if (isInbox(m.getType())){
   inflater.inflate(recv view);
 // it's been shortened 
} else {
   inflater.inflate(send view);   
// and determine the correct type of row layout
     // return 0 or 1
     // use the code that you currently have from the newView method
}
  • 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-06-08T05:00:39+00:00Added an answer on June 8, 2026 at 5:00 am

    But looking at my messages, the rows that are first shown when the
    listview are shown correctly, but when I go up the listview to new
    views, the layouts are mixed up.

    That is probably happening because you don’t handle the ListView recycling mechanism right. The newView method is not called for each row, it’s called when there isn’t a recycled view to be used for the row layout(like when the ListView is first shown, that’s why the rows appear in the correct order). Otherwise, the ListView will use a recycled view which may or may not be the right type of view.

    You should use the methods getViewTypeCount() and getItemViewType(). The method getViewTypeCount() will return two(as you have two types of rows?!?) and then implement the logic to determine the correct row type in the getItemViewType:

    @Override
    public int getViewTypeCount() {
        return 2;
    }
    
    @Override
    public int getItemViewType(int position) {
         Cursor c = (Cursor)getItem(position);
         Message m = Message.getMessage(context, c);
         switch(m.getType()){
             case Message.MMS_IN: // 128
                 return 1;
             case Message.MMS_OUT: // 132
                 return 0;
             case Message.SMS_IN: // 2
                 return 1;
             case Message.SMS_OUT: // 1
                 return 0;
             default:
                 return 0;
          }
    }
    

    Then in the newView method:

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        int rowType = getItemViewType(cursor.getPosition());
        if (rowType == 0){
            return mInflater.inflate(R.layout.messagelist_item_sent, parent, false);
        } else if (rowType == 1){    
            return mInflater.inflate(R.layout.messagelist_item_recv, parent, false);
        } else {
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom QGraphicsItem, that (among other things) changed the cursor to an
I have a custom CursorAdapter that is taking items from a database and displaying
I have a Listview with custom cursor adapter. I'm trying to prevent input in
i have cursor which selects records from my CarProfile table and use custom adapter
I have some custom, CoreAnimation based UI. I'd like to implement mouse dragging of
i have created a My custom listActivty by extending ListActivity like this. public class
I have created a custom Cursor Adapter for my list.The list gets some data
Background: I have a custom CursorLoader that works directly with SQLite Database instead of
I have a ListView with a custom adapter that extends CursorAdapter. that ListView also
I have a nicely working custom CursorAdapter with customized ListView. This view allows the

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.