GithubHelp home page GithubHelp logo

dvinfosys / navigation-listview Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 6.0 505 KB

This post is improvements to the previous posts discussed on customization of navigation drawer and highlighting specific row of expandable listview. Since there are few comments regarding the highlight of expandable list view post, thought to show with new post using custom navigation drawer. But how can we see the highlight of the expandable list view in handset, let’s take navigation drawer and customize it to use expandable list view.

License: Apache License 2.0

Java 100.00%
navigation-drawer expandablelistview custom-navigation-drawer android-navigation-drawer navigation navigation-menus navigation-listview

navigation-listview's Introduction

NavigationListView

License

This post is improvements to the previous posts discussed on customization of navigation drawer and highlighting specific row of expandable listview.

Since there are few comments regarding the highlight of expandable list view post, thought to show with new post using custom navigation drawer. But how can we see the highlight of the expandable list view in handset, let’s take navigation drawer and customize it to use expandable list view.

Before starting, I have faced few problems before starting expandablelistview and few questions are shown below. They are?

  1. How and why onchildclicklistener won’t respond but ongroupclicklistener responding?
  2. Whether we can have different background to the group view and child view?
  3. How to highlight the group row or child row on selecting?
  4. How to give the feedback on selection of other row when there is a highlight shown on the other row?

Add it in your root build.gradle at the end of repositories:

      allprojects {
          repositories {
            ...
            maven { url 'https://jitpack.io' }
          }
        }

Add the dependency

dependencies {
      implementation 'com.github.dvinfosys:Navigation-ListView:1.0.0'
}

Check out NavigationListView releases to see more unstable versions.

you could customize following UI controls in your Android application

xml

    <com.google.android.material.navigation.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_main">
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="170dp">
    
                <com.dvinfosys.ui.NavigationListView
                    android:id="@+id/navigation_list_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="left"
                    android:divider="@null"
                    android:groupIndicator="@null"
                    android:scrollbars="vertical" />
            </ScrollView>
    
        </com.google.android.material.navigation.NavigationView>

java

    NavigationListView listView= findViewById(R.id.navigation_list_view);
    listView.init(this)
                    .addHeaderModel(new HeaderModel("Home"))
                    .addHeaderModel(new HeaderModel("Cart",  R.drawable.ic_cardbackgroud, true,true, false, Color.WHITE))
                    .addHeaderModel(
                            new HeaderModel("Categories", -1,true)
                                    .addChildModel(new ChildModel("Men's Fashion"))
                                    .addChildModel(new ChildModel("Woman's Fashion"))
                                    .addChildModel(new ChildModel("Babies and Family"))
                                    .addChildModel(new ChildModel("Health"))
                    )
                    .addHeaderModel(new HeaderModel("Orders"))
                    .addHeaderModel(new HeaderModel("Wishlist"))
                    .addHeaderModel(new HeaderModel("Notifications"))
                    .build()
                    .addOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
                        @Override
                        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                            listView.setSelected(groupPosition);    
                            if (id == 0) {
                                //Home Menu
                                Common.showToast(context, "Home Select");
    
                                drawer.closeDrawer(GravityCompat.START);
                            } else if (id == 1) {
                                //Cart Menu
                                Common.showToast(context, "Cart Select");
                                drawer.closeDrawer(GravityCompat.START);
                            } /*else if (id == 2) {
                                //Categories Menu
                                Common.showToast(context, "Categories  Select");
                            }*/ else if (id == 3) {
                                //Orders Menu
                                Common.showToast(context, "Orders");
                                drawer.closeDrawer(GravityCompat.START);
                            } else if (id == 4) {
                                //Wishlist Menu
                                Common.showToast(context, "Wishlist Selected");
                                drawer.closeDrawer(GravityCompat.START);
                            } else if (id == 5) {
                                //Notifications Menu
                                Common.showToast(context, "Notifications");
                                drawer.closeDrawer(GravityCompat.START);
                            }
                            return false;
                        }
                    })
                    .addOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                        @Override
                        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                            listView.setSelected(groupPosition, childPosition);
                            if (id == 0) {
                                Common.showToast(context, "Man's Fashion");
                            } else if (id == 1) {
                                Common.showToast(context, "Woman's Fashion");
                            } else if (id == 2) {
                                Common.showToast(context, "Babies and Family");
                            } else if (id == 3) {
                                Common.showToast(context, "Health");
                            }
    
                            drawer.closeDrawer(GravityCompat.START);
                            return false;
                        }
                    });
            //listView.expandGroup(2);

Output

ExpandableListView Show

ExpandableListView Hide

navigation-listview's People

Contributors

dvinfosys avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

navigation-listview's Issues

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.