Giter Site home page Giter Site logo

android-staticlist's Introduction

Android Static List

Usage

1.- Configuring your Project Dependencies

Add the reference to the Bintray repository in your project-level build.gradle file.

allprojects {
  repositories {
    // ...
    maven { url 'https://dl.bintray.com/luisburgos/staticlist' }
  }
}

The, Add the library dependency to your module-level build.gradle file.

dependencies {
  // ...
  compile 'com.luisburgos:staticlist:0.1.0'
}

2.- Configure your fragment

Extend your Fragment from StaticListFragment and override

public class MyStaticListFragment extends StaticListFragment {

    @Override
    protected List<StaticListItem> setupStaticListItems() {
        List<StaticListItem> items = new ArrayList<>();

        items.add(new StaticListItem("Option 1", StaticListItem.TYPES.BASIC_RIGHT_DETAIL));
        items.add(new StaticListItem("Option 2", StaticListItem.TYPES.BASIC));
        items.add(new StaticListItem("Option 3", StaticListItem.TYPES.BASIC_RIGHT_DETAIL));

        return items;
    }

    public static MyStaticListFragment newInstance() {
        Bundle arguments = new Bundle();
        MyStaticListFragment fragment = new MyStaticListFragment();
        fragment.setArguments(arguments);
        return fragment;
    }
}

3.- Setup the Item Listener

Implement the interface OnStaticListItemClickListener provided by the StaticListRecyclerViewAdapter class

public class MyStaticListFragment extends StaticListFragment implements StaticListRecyclerViewAdapter.OnStaticListItemClickListener {

    ...

    @Override
    public void onItemClick(StaticListItem item) {
        Toast.makeText(getContext(), "Click item " + String.valueOf(item.getTitle()), Toast.LENGTH_SHORT).show();
    }

    ...
}

4.- Make sure to set the Listener properly

Override the onCreate method in order to set the listener to the StaticListFragment

public class MyStaticListFragment extends StaticListFragment implements StaticListRecyclerViewAdapter.OnStaticListItemClickListener {

    ...

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setOptionsListener(this);
    }

    ...
}

NOTE: You can see another ways of use here

Developed By

License

Copyright 2017 Luis Burgos

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.

android-staticlist's People

Contributors

luisburgos avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.