Published on Feb 20,2015
Email Post

You have already created a few basic Android apps; it is now time for you to learn how to create Android widgets. If you are not clear with the basic concepts of Android, please attend this Android Course.

What are Widgets in Android?

For sure, all you folks are aware of the concept of Widgets in Android. For the benefit of the curious newbies, let me simplify it a little. The nice little weather bar and clock on your mobile screen, the music player controller that allows you to play a song without going to the music player application; they are all widgets.

Widgets are, in essence, miniature application views that can interact with the user. They are capable of performing a lot more functions than just providing shortcuts to applications.

Categories of Widgets

Before learning how to create Android widgets, it is important for you to understand the different categories of widgets. The Official Android website has defined the following categories:

1) Information Widgets:

These widgets display a piece of information, for instance the weather widget.

How to create Android widgets: Information widget

2) Collection Widgets:

These widgets help the user put together multiple elements of the same kind, for instance, the widgets that help organize all your email messages together.

Message widget in Android

3) Control Widgets:

Control Widgets display the often-used functions, so that the users can perform the tasks without actually going to the application screen. For instance, the WiFi toggle widget, that can help you turn the WiFi on your device ‘on’ or ‘off’.

WiFi toggle widget

4) Hybrid Widgets:

Many widgets combine the functionality of more than one type; for instance the Music Player. Not only does it allow the users to change the track (Control Widget), but also updates the user about the track that is playing (Information Widget).

How to create Android widgets: Music Player widget

How to create Android Widgets: RatingBar

It is now time to learn how to create Android widgets. In this tutorial, we will help you create a RatingBar Widget.

How to create Android widgets: RatingBar widget

It is a very useful widget especially when you want a feedback from your users. The user can touch/drag or use arrow keys to set the rating when using the RatingBar. You must remember that placing widgets to the left or right of the RatingBar is discouraged.

How to write an application for RatingBar?

You can create a nice little RatingBar Widget by following these four steps. This is how the Rating bar would finally look:

How to create Android widgets: RatingBar widget final overviewStep 1: Create a new Android Application Project.

Step 2: In the XML file, drag a RatingBar from “Form Widgets” or write the following XML code.

XML Code:

Step 4: Working with RatingBar is very simple; you only have to use setOnRatingBarChangeListener with RatingBar.

Step 5: Inside the onCreate() method copy the following code:

Java Code:

RatingBar rbar = (RatingBar)findViewById(;

rbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {


public void onRatingChanged(RatingBar ratingBar, float rating,

boolean fromUser) {

Toast.makeText(MainActivity.this, "Rating : " + rating,




[dl url=”#” class=”eModal eModal-9″ title=”Download Code” desc=”” type=”” align=”” for=”download”]


float rating: This gives you current rating value on the RatingBar.

boolean fromUser : This gives you ‘true’ if the rating is changed by user.

Got a question for us? Mention them in the comments section and we will get back to you.

Related Posts:

Beginner’s Guide to Android Architecture

Android Development Course


Share on

Browse Categories