We used cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. What For?

« Back to Blogs

Web Content list screenlet for Android

What is Screenlet ??


Liferay provides the screenlets, which are the readymade screen for the faster android app development for Liferay apps. Liferay Screens for Android contains several Screenlets that you can use in your Android apps.


Liferay screenlet is Java view classes, which can be inserted into a layout of an activity or fragment. They render a selected layout in the runtime and in Android Studio’s visual editor and react to UI events, sending any necessary server requests. You can set a Screenlet’s properties from its layout XML file and Java classes. The Screenlets bundled with Liferay Screens are known collectively as the Screenlet Library. Let’s understand by implementing.


Environment Details:

  • Liferay portal version:  Liferay 7 CE GA3

  • Android Studio version:  2.2.3


Prerequisite :


  • Configure your Android Studio project for using the Liferay Screens. Click here for a reference.

  • Configure Liferay instance to connect with for your android application.

Today we are going to look into detail how to use web content list screenlet in your app. Liferay provides many screenlets, out of we are going to use


  1. Login screenlet

  2. Web content list screenlet

Let’s get started …


1. Create new android studio project “ScreenletDemo” with blank activity.

2. Add Liferay libraries for using screenlets by adding,


compile 'com.liferay.mobile:liferay-screens:+'

compile 'com.liferay.mobile:liferay-material-viewset:+'


In your build.gradle(app) file in dependencies,

When you Sync your project, you will have access to screenlets provided by a library.


3. Configure login Screenlet for logging into Liferay instance.

  • Configure UI for logging activity by adding the following code in your activity_main.xml


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




  xmlns:liferay "http://schemas.android.com/apk/res-auto"











      liferay:layoutId="@layout/login_default" />





As in code highlighted code is for adding the readymade views to display in our apps. For using any Liferay functionality user must be authenticated. Login Screenlet takes care of it very well.


  • Configure server_context.xml file under your res/values folder


You will need to provide configuration details here, which screenlet takes as a reference.



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


  <string name="liferay_server"></string>

  <integer name="liferay_company_id">20116</integer>

  <integer name="liferay_portal_version">70</integer>



liferay_server : Server address of your Liferay instance is running.

liferay_company_id : Company id for the instance

liferay_portal_version : Liferay version server is running Liferay 6 (62), Liferay 7 (70)


  • Configure MainActivity.java file.

  • Screenlet provides the interfaces to get a result of web service calls by mobile SDK. For login, you need to implement LoginListener, which provides two methods that you need to implement.


First, set the listener for in onCreate method of MainActivity  by




protected void onCreate(Bundle savedInstanceState) {



  LoginScreenlet loginScreenlet = (LoginScreenlet) findViewById(R.id.login_screenlet);





Now, you will get the callback for the login when you successfully logged in




public void onLoginSuccess(User user) {


  Toast.makeText(getApplicationContext(),user.getScreenName()+"Successfully logged in",Toast.LENGTH_LONG);




Or in Failure.




public void onLoginFailure(Exception e) {





3. Configure “Web content list” screenlet.

  • Create new activity named WebContentListActivity for listing the web content inside the activity.

  • Configure the UI in activity_web_content_list.xml with the screenlet  ,














There are several attributes you will need to consider when setting up the UI.




The ID of the layout to use to show the View.



Whether the list loads automatically when the Screenlet appears in the app’s UI. The default value is true.



The ID of the web content folder to retrieve content from.



The comma-separated names of the DDM fields to show. Refer to the list’s data definition to find the field names. For more information on this, see the article on structured web content. Note that the appearance of data from a structure’s fields depends on the layoutId.



Note: All attribute can be found at link


  • Configure the WebContentListActivity.java for web content listing.


You need to configure the listener for getting the event for a listing of the web content in your activity's onCreate() method as below.




protected void onCreate(Bundle savedInstanceState) {




  WebContentListScreenlet webContentListScreenlet = (WebContentListScreenlet) findViewById(R.id.web_content_screenlet);





For listeners, you need to implement BaseListListener  an interface in your activity. Using the interface you need to implement following methods in your activity.




  public void onListPageFailed(int startRow, Exception e) {




      Called when the server call to retrieve a page of items fails.

      This method’s arguments include the Exception generated when the server call fails.





  public void onListItemSelected(Object element, View view) {

      Log.d(TAG,"list item selected");



      Called when an item is selected in the list.

      This method’s arguments include the selected list item (Record).





  public void onListPageReceived(int startRow, int endRow, List entries, int rowCount) {

      Log.d(TAG,"list page received called");



      Called when the server call to retrieve a page of items succeeds.

       Note that this method may be called more than once;

        once for each page received. Because of startRow and endRow change for each page,

         a startRow of 0 corresponds to the first item on the first page.





  public void error(Exception e, String userAction) {




3. Loading the web content in the list Screenlet.


Here, you need to implement the intent in MainActivity.java to redirect on WebContentListActivity.java when user successfully logged in,


For that, update MainActivity’ s onLoginSuccess()  Method.




public void onLoginSuccess(User user) {


  Toast.makeText(getApplicationContext(),user.getScreenName()+"Successfully logged in",Toast.LENGTH_LONG);


  Intent intent = new Intent(this, WebContentListActivity.class);





So, when the user logged in successfully, will be redirected to WebcontentListActivity.java and show a list of web contents.


Reference :



For more information or implementation details, you may contact us at [email protected]

contact-us Request a callback WhatsApp