GithubHelp home page GithubHelp logo

talhahasanzia / three-level-expandable-listview Goto Github PK

View Code? Open in Web Editor NEW
35.0 5.0 6.0 2 MB

:clipboard: 3-level expandible ListView for android.

License: Apache License 2.0

Java 100.00%
android expandablelistview nested-listview listview

three-level-expandable-listview's Introduction

License

Three Level Exapandable List View

This is boiler plate code to implement 3-level exapandable list view in Android. This code will work with dynamic data, an extension of its gist which works only on static string text values.

Demo gif

  • Code is not using ViewHolder pattern hence it is not recycled.
  • Code is not memory efficient.

Getting Started

  • Download or clone project
  • Define parent array for main category, parent is top level list.
    String[] parent = new String[]{"MOVIES", "GAMES"};
  • Define array for genre (subcategory) for each parent category added this is level 2, eg:
   String[] movies = new String[]{"Horror", "Action", "Thriller/Drama"}
   String[] games = new String[]{"Fps", "Moba", "Rpg", "Racing"};

  • Define level 3 elements in separate arrays:
 
    String[] horror = new String[]{"Conjuring", "Insidious", "The Ring"};
   
    String[] action = new String[]{"Jon Wick", "Die Hard", "Fast 7", "Avengers"};
    
    String[] thriller = new String[]{"Imitation Game", "Tinker, Tailer, Soldier, Spy", "Inception", "Manchester by the Sea"};

    String[] fps = new String[]{"CS: GO", "Team Fortress 2", "Overwatch", "Battlefield 1", "Halo II", "Warframe"};
   
    String[] moba = new String[]{"Dota 2", "League of Legends", "Smite", "Strife", "Heroes of the Storm"};
    
    String[] rpg = new String[]{"Witcher III", "Skyrim", "Warcraft", "Mass Effect II", "Diablo", "Dark Souls", "Last of Us"};
    
    String[] racing = new String[]{"NFS: Most Wanted", "Forza Motorsport 3", "EA: F1 2016", "Project Cars"};


  • Define a secondLevel ArrayList, this will be used as key data to fetch arrays accross levels.

  • Define LinkedHasMap for each subcategory where key is subcategory name, and value is a string array,

    LinkedHashMap<String, String[]> thirdLevelMovies = new LinkedHashMap<>();

    LinkedHashMap<String, String[]> thirdLevelGames = new LinkedHashMap<>();
    
    ...now putting it all together
    
        secondLevel.add(movies);
        secondLevel.add(games);
        
        thirdLevelMovies.put(movies[0], horror);
        thirdLevelMovies.put(movies[1], action);
        thirdLevelMovies.put(movies[2], thriller);
        
        thirdLevelGames.put(games[0], fps);
        thirdLevelGames.put(games[1], moba);
        thirdLevelGames.put(games[2], rpg);
        thirdLevelGames.put(games[3], racing);
        
        data.add(thirdLevelMovies);
        data.add(thirdLevelGames);
        
        expandableListView = (ExpandableListView) findViewById(R.id.expandible_listview);
        ParentLevel parentLevelAdapter = new ParentLevel(this, parent, secondLevel, data);
        expandableListView.setAdapter(parentLevelAdapter);   
    

Built Using

  • Android Studio 2.3.2
  • Min SDK 16, Target SDK 25
  • Build Tools 25.0.3
  • Gradle 2.3.2

Code will work fine as long as above configurations are met.

You will need to possibly edit code if you change min sdks etc.

Contributing

Anyone is allowed to fork and create a pull request provided that the code is improved in anyway.

Authors

See also the list of contributors who participated in this project.

License

Copyright 2017 Talha Hasan Zia

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.

See the LICENSE.md file for details

three-level-expandable-listview's People

Contributors

talhahasanzia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

three-level-expandable-listview's Issues

Set negative margin in third lvl child item.

Set a negative margin in third-level child item i.e XML, as childDividerheight doesn't exist, and adding a negative margin on root layout of the third list item doesn't work. Any solutions?

When the last child-view is clicked , list should remain open

I set listeners to last child that will trigger when user clicks and send it to another activity. When I get back, I see that list closed. I want this list to be remained open when this navigation happens. I donot call any collapse methods in onPause(), onStop() methods, but 2nd level of listview is completely collapsed.

User should see exact lists opened where he left when he clicked to move to other activity.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.