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

  • SEARCH
  • Home
  • 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 8408305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:35:45+00:00 2026-06-09T23:35:45+00:00

I display the information using Listview . However, I have two types of layout

  • 0

I display the information using Listview. However, I have two types of layout file depends on the information_type.

If information_type is 1, I will use one layout file.And if information_type is 2, I will use another layout file.When the ListView loaded, it will automatically go to bottom.

For example at the beginning, I have 40 list items.When the ListView is loaded, for the bottom 4-5 items, it displays using correct layout file.

However, when I scroll the ListView upper and then scroll down, the bottom 4-5 items changes their layout file.

Every time I scroll up and down, the list items(layout file) may changes usually.
Here is my code.

public class CustomCursorAdapter extends SimpleCursorAdapter{

    private int layout;

    public CustomCursorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.layout = layout;
    }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent){
        ViewHolder holder = new ViewHolder();
        View v;

        final LayoutInflater inflater = LayoutInflater.from(context);           
        int col_type = cursor.getColumnIndex(KEY_MESSAGE_TYPE);
        String type = cursor.getString(col_type);
        Log.d(TAG, "in newView: type is:" + type);          
        if (type.equalsIgnoreCase("1")){
            Log.d(TAG, "in newView: receive message");
            v = inflater.inflate(R.layout.sub_chat_view_in, parent, false);
            holder.tv_title = (TextView)v.findViewById(R.id.titleIn);
            holder.tv_message = (TextView)v.findViewById(R.id.messageIn);
            holder.tv_time = (TextView)v.findViewById(R.id.timeIn);
        }else{
            Log.d(TAG, "in newView: send message");
            v = inflater.inflate(R.layout.sub_chat_view_out, parent, false);
            holder.tv_title = (TextView)v.findViewById(R.id.titleOut);
            holder.tv_message = (TextView)v.findViewById(R.id.messageOut);
            holder.tv_time = (TextView)v.findViewById(R.id.timeOut);
        }
        v.setTag(holder);
        return v;
    }
    @Override
    public void bindView(View v, Context context, Cursor c){
        ViewHolder holder = (ViewHolder) v.getTag();

        int col_owner = c.getColumnIndex(KEY_OWNER_NAME);
        int col_target = c.getColumnIndex(KEY_TARGET_NAME);
        int col_type = c.getColumnIndex(KEY_MESSAGE_TYPE);
        int col_message = c.getColumnIndex(KEY_MESSAGE_CONTENT);
        int col_time = c.getColumnIndex(KEY_TIME);

        String owner = c.getString(col_owner);
        String target = c.getString(col_target);
        String type = c.getString(col_type);
        String message = c.getString(col_message);
        String time = c.getString(col_time);


        if(type.equalsIgnoreCase("1")){
            holder.tv_title.setText("From " + target);
        }else{
            holder.tv_title.setText("To " + target);
        }
        holder.tv_message.setText(message);
        holder.tv_time.setText(time);
    }
    class ViewHolder {
        TextView tv_title;
        TextView tv_message;
        TextView tv_time;
    }
}
  • 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-09T23:35:46+00:00Added an answer on June 9, 2026 at 11:35 pm

    Try to override next methods:
    public int getViewTypeCount() and public int getItemViewType(int position)

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

Sidebar

Related Questions

i want to display some information in a listview using the GridView. i have
I am using a popup window to display some information and have an edit
I have a WPF program with two listviews which display information from two different
I have a program where I am using a JScrollPane to display information I
I have an EditText view which I am using to display information to the
I am using Telerik treeview in MVC3 Razor view to display tree structured information.
I'm using a bit of JSON to parse information from facebook pages to display
I have a very general web page where I display information. I have this
I have a ViewPager and it is using a FragmentAdapter in order to display
I am using DevExpress GridControl to display information from my database through a stored

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.