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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:22:49+00:00 2026-06-10T18:22:49+00:00

I have a BaseAdapter that manages the rows in my ListView . All this

  • 0

I have a BaseAdapter that manages the rows in my ListView. All this while I’ve been displaying the records in the listview without any grouping or headers and it has worked fine. My adapter uses an ArrayList and for a non-grouped set of data, it works just fine. Here’s what it looks like:

public class SearchResultsAdapter extends BaseAdapter {

  public ArrayList<Result> objResults;

  public SearchResultsAdapter(Search ctxContext, ArrayList<Result> objResults) {
    this.objResults = objResults;
  }

  public View getView(int position, View convertView, ViewGroup parent) {    
    if (check whether it is a category) {    
      View v = mInflater.inflate(R.layout.category, null);

      final TextView sectionView = (TextView) v.findViewById(R.id.text);
      sectionView.setText("New Category");

      return v;    
    } else {
      View vewRow = mInflater.inflate(R.layout.row, null);

      TextView tvwName = (TextView) vewRow.findViewById(R.id.name);
      tvwName.setText(objResults.get(position).getName());

      return vewRow;    
    }    
  }

}

When the getView method of the adapter is invoked internally, it only expects it to return a single row from my collection at that position.

Ideally I could has used a HashMap as I could have grouped my data and stored the data of each group under a key in the map but I can’t reference HashMap items by a simple position as I can with an ArrayList; it’s only logical.

I’ve seen a lot of apps use the ListView to show both headers and rows but I haven’t understood what collection/pattern is best suited for this.

Thanks.

  • 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-10T18:22:51+00:00Added an answer on June 10, 2026 at 6:22 pm

    As per Samir’s comment and example:

    Create and an ArrayList of a custom Interface. Create two classes – Row and Section that implement that custom Interface and then when returning the row in the getView method of the BaseAdapter, return the correct view i.e. row or section based whether the object in the list at that position is a Row or a Section.

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

Sidebar

Related Questions

I have a gallery that's loaded via a BaseAdapter . This works fine. I
When overriding the baseadapter on an android listview, you have to implement this method
First of all I have a simple ListView . Implementing the BaseAdapter and utilizing
I have a ListView with a custom list adapter (that extends BaseAdapter). My list
I have a listview that uses a customadapter based on the baseadapter. The listview
I have a ListView with BaseAdapter and I create this adapter in my main
I have a custom baseadapter that i use to populate a listview. each row
I have Vector of elements that i set into BaseAdapter subclass and this adapter
Im using a BaseAdapter and passing to it a List of objects that have
I have a listview, baseadapter and data from SQLite, including a BLOB. What if

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.