• This repository has been archived on 20/Oct/2022
  • Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language
    Java
  • Created over 12 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The SIMPLEST Section Adapter for Android

Notice

Simple Section Adapter is now part of an even more awesome Adapter Kit project!

About

This is the SIMPLEST Section Adapter available for Android's ListView. It works with list adapters that you already have. No project specific dependencies. Just include the latest jar or the sources to your Android project.

Pros

  • The simplest implementation yet, you can create a sectioned ListView with just 6 lines of code.
  • Zero project specific dependencies.

Compatibility

  • Android 1.6 and up

Usage

// 1. Create a Sectionizer    
class BookSectionizer implements Sectionizer<Book> {

    @Override
    public String getSectionTitleForItem(Book book) {
        return book.getGenre();
    }
}

// 2. Wrap your existing adapter with the SimpleSectionAdapter
SimpleSectionAdapter<Book> sectionAdapter = new SimpleSectionAdapter<Book>(context, 
        yourBookAdapter, R.layout.section_header, R.id.title, 
        new BookSectionizer());
    
// 3. Set the SimpleSectionAdapter to your ListView
listView.setAdapter(sectionAdapter);

Also you can check a complete example for a quick start. The sources have a few more examples as well.

NOTE: The data source (Cursor, ArrayList or Array) provided to your Adapter should be sorted in a logical way you want them to be sectioned. For instance, if you want to section your books by genres, they have to be sorted by genres before you wrap it within the SimpleSectionAdapter.

Screenshots

 

OnItemClickListener

While using an OnItemClickListener instead of using the list item's position directly, use it as shown below.

@Override
public void onItemClick(AdapterView<?> parentView, View view, int position, long id) {
    // 1. You could do this
    City city = (City) sectionAdapter.getItem(position);
        
    // 2. Or you could do this :)
    int index = sectionAdapter.getIndexForPosition(position);
    City sameCity = cities.get(index);

    // More code…
}

FAQs

  • Can I use SimpleSectionAdapter with ArrayAdapter or CursorAdapter?
    Yes, you can use SimpleSectionAdapter with any adapter that extends BaseAdapter.

  • Should I sort my data in my data source source (Cursor, ArrayList or Array) logically in the order they have to be sectioned?
    Yes, you have to sort your data, SimpleSectionAdapter does not perform sorting.

  • Are there any resource files that has to be included with my project?
    No, you don't have to include anything besides the SimpleSectionAdapter and the Sectionizer.

License

Copyright 2012 Mobs and Geeks

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

android-saripaar

UI form validation library for Android
Java
3,228
star
2

adapter-kit

Adapter Kit is a set of useful adapters for Android.
Java
364
star
3

instant-adapter

Just like instant coffee, saves 78% of your time on Android's Custom Adapters.
Java
231
star
4

kaffeine

Kaffeine is a Kotlin-flavored Android library for accelerating development.
Kotlin
156
star
5

android-typeface-textview

[DEPRECATED] TextView that allows custom typefaces from XML
Java
73
star
6

circular-list-adapter

A simple Circular List Adapter for Android
Java
31
star
7

upi-dropin

Implementation of NPCI's UPI Linking Specifications Version 1.1 (Draft) for Android.
Java
30
star
8

OneWay

A unidirectional reactive functional architecture library for Android and the JVM.
Kotlin
25
star
9

keylines

Painlessly build and ship apps that conform to the Material design specifications
Java
18
star
10

RxBuddies

Kotlin
12
star
11

kotlin-refactoring-katas

A collection of katas either copied or ported from some amazing folks.
Kotlin
12
star
12

versioning-tdd-kata

A kata to learn and practice TDD
Kotlin
9
star
13

deselectable-radio-button

Deselectable Radio Button for Android
Java
8
star
14

bench-press

Android starter project to evaluate architectures and build muscle memory.
Kotlin
6
star
15

all

An experimental library for dealing with legacy code
Kotlin
5
star
16

scalaxia-android

Android client for Scalaxia
4
star
17

liberate

A command-line utility to run ADB over Wi-Fi on Android devices.
Ruby
4
star
18

ensemble-kata

Kotlin
3
star
19

hello-git

1
star
20

xstate-spike

XState proof of concept in Kotlin
Kotlin
1
star