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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:19:29+00:00 2026-06-09T04:19:29+00:00

I have a very simple ListView right now in a ListActivity that displays just

  • 0

I have a very simple ListView right now in a ListActivity that displays just a list of text values. Here’s my current code:

public class InfoActivity extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        List<String> values = new ArrayList<String>();
        // loads up the values array here
        // ...

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
        setListAdapter(adapter);
    }

My XML file for InfoActivity has nothing in it because I am using a ListActivity.

What I want to do it make custom layouts for the rows. The first 5 rows will have layoutA.xml and the second 5 rows will have layoutB.xml.

How do I do this? I’m lost on where to begin. Obviously I’m looking for the simplest code possible.

  • 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-09T04:19:32+00:00Added an answer on June 9, 2026 at 4:19 am

    This is easy enough, you simply need to extends ArrayAdapter. My ArrayAdapter does two things differently:

    • instead of passing one ResourceId, my adapter take an array of ResourceIds
    • getView() checks the position and loads the appropriate resource

    This is a trivial example. If you plan on making it more complex than the first half looks one way and the second half is different, then you should override getViewTypeCount() and getItemViewType().

    Working example:

    public class Example extends Activity {
        public class MyArrayAdapter<T> extends ArrayAdapter<T> {
            LayoutInflater mInflater;
            int[] mLayoutResourceIds;
    
            public MyArrayAdapter(Context context, int[] textViewResourceId, List<T> objects) {
                super(context, textViewResourceId[0], objects);
                mInflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
                mLayoutResourceIds = textViewResourceId;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                if (convertView == null && position > 2)
                    convertView = mInflater.inflate(mLayoutResourceIds[1], parent, false);
                return super.getView(position, convertView, parent);
            }
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            String[] array = new String[] {"one", "two", "three", "four", "five", "six"};
            List<String> list = new ArrayList<String>();
            Collections.addAll(list, array);
    
            ListView listView = new ListView(this);
            listView.setAdapter(new MyArrayAdapter<String>(this, new int[] {android.R.layout.simple_list_item_1, android.R.layout.simple_list_item_single_choice}, list));
            setContentView(listView);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys i have a ListActivity... a very simple at that... and it keeps
I have an ASP ListView, and have a very simple requirement to display numbers
I have a custom listview and made overlapping very simple: in onDraw method, I
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
I have very simple application just in the body of Main method. I have
I have very simple XML in a string that I'm trying to load via
I have very simple code: List<String> list = new ArrayList<String>(); String a = a;
I have developed a very simple app that uses a custom adapter for a
I have a simple ListView and on that ListView I have placed a number
i have very simple problem. I need to create model, that represent element of

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.