Posts

Showing posts from 2016

Dynamically change ListView to GridView and Vice Versa using RecyclerView

Image
We can change the RecyclerView from type of ListView to GridView in single line of code.

Video output of sample project

code is:

private void setLayoutManager() { if (mColumnCount <= 1) { mColumnCount = 1; recyclerView.setLayoutManager(new LinearLayoutManager(context)); } else { recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount)); } }
Video output of sample project:




I hope this post is useful to you. kindly share your feedback as comment here.


Simple RecyclerView example in Android

Simple RecyclerView example with filter option in Android

Simple recyclerview example with checkbox in Android

Source code on GitHub



Thank You

Simple recyclerview example with checkbox in Android

Image
Good morning to all, Those who all tried RecyclerView adapter with CheckBox, you all may find the issue on dynamic data change in RecyclerView. This will help you to resolve the issue in very simple way.

Video output of this project

So how to achieve this task effectively?

Simple, I hope you all tried with list objects only. Surely this object will have the boolean variable to know whether this object is selected or not. So now while we are select one object with the help of recyclerview and scroll down and up recyclerview adapter, the checked checkbox's position may change, this reflects on our object also, So how to avaid this issue.

simple, In our recyclerview adapter's onBindViewHolder method, first set the checkedOnChangeListener of checkbox to null, and then set whether this object is selected or not to checkbox, and then add the checkedOnChangeListener to the checkbox. That's all. Issue solved.

onBindViewHolder will be look like
@Override public void…

Simple RecyclerView example with filter option in Android

Image
Hi Guys, Maybe you all are expert in terms of using RecyclerView in android. This blog is simple example for using filter option with RecyclerView adapter.



As for now you will instantiate RecyclerView and set the adapter to RecyclerView as following way. RecyclerView list = (RecyclerView) findViewById(R.id.list); list.setLayoutManager(new LinearLayoutManager(this)); list.setHasFixedSize(true); ArrayList&ltNumber&gt numbers = new ArrayList&lt&gt(); String ONEs[] = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN"}; String TENs[] = {"ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY", "HUNDRED"}; String HUNDREDS[] = {"ZERO", "HUNDRED", "TWO HUNDRED&q…

Simple example of Navigation view on both side in Android

Image
Hi guys, you can use NavigationView on both side if you want side menu in both left and right side in Android as following.


Your drawer layout will be &lt?xml version="1.0" encoding="utf-8"?&gt &ltandroid.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"&gt &ltinclude layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent" /&gt &ltandroid.support.design.widget.NavigationView android:id="@+id/nav_view" …

NavigationView example in Android

Image
Hi guys, You can use NavigationView from android material design for slide menu in android.


DrawerLayout xml &ltandroid.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"> &ltinclude layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent" /&gt &ltandroid.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_width="wrap_content" android:layout_height="match_parent" …