Dive into Java Method Overloading

Method overloading allows a class to have two or more methods having same name. But there are some conditions applied if you overload a method. Let’s discuss on then.

First of all we should know “ Why do we use method overloading in Java?” .

Suppose we have to perform addition of given number but there can be any number of arguments, if we write method such as methodAddTwoNo(int a, int b) for two arguments, methodAddThreeNo(int a, int b, int c) for three arguments then it is very difficult for you and other programmer to understand purpose or behaviors of method they can not identify purpose of method. So we use method overloading to easily figure out the program. For example above two methods we can write sum(int a, int b) and sum(int a, int b, int c) using method overloading concept.

So it is clear that to achieve method overloading concept methods should have same name but with different parameters.

But what will happen if we put methods name same and also the same parameters.

Let’s see: Continue reading

Advertisements

Implement Android Data Binding library in your android app: Part-2

In Part-1 we discussed about how to implement Android Data Binding library in your android app. In this part we will see how we can bind data within our layout xml files and also the clickListeners on buttons.

Data-binding layout files are slightly different and start with a root tag of layout followed by a data element and a view root element. This view element is what your root would be in a non-binding layout file. A sample file looks like this: Continue reading

RecyclerView with EndlessScroll With Android Data Binding

A common application feature is to load automatically more items as the user scrolls through the items (aka infinite scroll). This is done by triggering a request for more data once the user crosses a threshold of remaining items before they’ve hit the end.

Implementing endless pagination for RecyclerView requires the following steps:

  1. Copy over the EndlessRecyclerViewOnScrollListener.java into your application. This is an abstract class.
  2. Now call addOnScrollListener() on your RecyclerView to enable endless scrolling and pass EndlessRecyclerViewOnScollListener as parameter in addOnScrollListener() and implement onLoadMore() method which would be called when user scroll down bottom in the list.
  3. In onLoadMore() method load your data using an api or some source from where you are fetching data.

Continue reading

Let’s implement Android Data Binding library in your android app: Part-1

Now there is no need for the third party libraries to bind views and data for better coding, because android recently introduced a new feature for this.

Android Data Binding is one of the most interesting feature recently introduced but still in beta version.

Android Data Binding exist between app presentation layer and data model layer that holds the information to show. Continue reading