Skip to content
Related Articles

Related Articles

Improve Article

Android View Evolution – PlaceHolderView

  • Last Updated : 11 Jun, 2021

Those days are gone when ListView, GridView, RecyclerView, and Pesky Adapters ruled the arena. Say Hello to PlaceHolderView ???? Adding listeners to each RecyclerView and implementing dynamic content is a tedious operation. Let’s not even talk about animation; if we have to perform it for nested Recyclers, it’ll be a disaster. What if we could replace ListView, GridView, and RecyclerView with ease and simplicity by using a very basic interface with additional capability and no adapter implementation?

What is the Purpose of the PlaceHolderView Class?

PlaceHolderView automates the process of configuring View adapters by removing all of the boilerplate code. The incredible thing is that there is no need for an adaptor. The code becomes incredibly modular, and the ability to add annotations to any view or method gives it a lot of flexibility. There are no unsightly codes like findViewById or onClickListener.

  • With just one line of code, you can create amazing animations for the view objects.
  • Memory management is a breeze.

How to Introduce this Great View in The project?

Well, the answer is pretty simple. PlaceHolderView is a view that allows you to see what’s going on. Some of the views in the PlaceHolderView library are based on RecyclerView, while the others are created from scratch. To produce the binding classes, all of the annotations are processed during the build process. There are two different variants to choose from.

  1. Uses Java reflection in the older version (branch 1.x).
  2. Annotation Processing is now supported in the new version (branch 2.x).

To add this library to your Android Project simply put up this line in your Gradle (project) and then hit ‘Sync’


implementation ''
implementation ''
implementation ''
kapt ''

And then magically the PlaceHolderView is added to your current Android Project

Step #1: In the XML layout, create a PlaceHolderView.After that you need to tweak your XML files and add or replace the current view, to do so, just follow the below code snippet



Now Step #2: Create the view of the items which you need to inflate in your PlaceHolder View


<?xml version="1.0" encoding="utf-8"?> 

Step #3: Now in the MainActivity or Adapter Activity Java file just bind the methods so that they can be identified during the runtime


public class GeeksImage {
    @View( private ImageView imageView;
    private String mUrl;
    private Context mContext;
    private PlaceHolderView mPlaceHolderView;
    public ImageTypeBig(Context context,
                        PlaceHolderView placeHolderView,
                        String url)
        mContext = context;
        mPlaceHolderView = placeHolderView;
        mUrl = url;
    @Resolve private void onResolved()
    @LongClick( private void onLongClick()

Step #4. For this last step just inflate the views to the placeholder view and you are good to go 


PlaceHolderView mGalleryView = (PlaceHolderView)findViewById(;
.setLayoutManager(new GridLayoutManager(this, 3));
mGalleryView.addView(new GeekImage(this.getApplicationContext(), mGalleryView, url1));
.addView(new GeekImage(this.getApplicationContext(), mGalleryView, url2));
.addView(new GeekImage(this.getApplicationContext(), mGalleryView, url3));
.addView(new GeekImage(this.getApplicationContext(), mGalleryView, url4));

That’s it!

You just mastered the art of using PlaceHolderView and you will never look back to the older view options, and will now seem amazingly inferior. 

GeekTip: PlaceHolderView will recycle viewItems and attempt to refill the data of the current viewItem with similar/same viewtype viewItems. As a result, whenever the viewItem is associated to the window, the method annotated with @Resolve will be invoked. That is, if you don’t explicitly populate the viewItem in a method annotated with @Resolve, that viewItem may display the history of a previously used viewItem.

Rather than using a method marked with @Resolve, try to instantiate any class in the function Object() { [native code] }. 

Make the list empty initially if the itemView contains PlaceHolderView/ListViews and the item is being added using a method marked with @Resolve. This is necessary because if the recycled view contains PlaceHolderView/ListViews of other itemViews, duplicate viewitems may be inserted. Before adding views to a method marked with @Resolve, use removeAllViews() for PlaceHolderView.

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :