How to ask users nicely to review your Android app using Kotlin
- July 28, 2019
- John Codeos
A very usual method that developers use to ask their users for an app review is to show a pop-up dialog after a couple of starts of their app.
The problem with that is users will ignore it easily because you interrupt their experience.
To fix this problem, we will implement this thing inside in a RecyclerView.
First, we have to add the library to our dependencies inside the build.gradle file
In colors.xml file, inside the folder values, we’re adding the background and text color we want our rate view to have.
Now, we need to add our RecyclerView row layout which contains the view, by making a new XML file under the layout folder named review_row.xml
Let’s go now and set up how frequent we’re going to ask our users to review our app by adding in our Application() file (or MultiDexApplication()) the following code:
If you don’t have any Application() file on your project, create a new Kotlin file and paste the code above. After that, go your AndroidManifest.xml and add
android:name=".Application" inside the tag
<application> like this:
After we finished with all that, let’s add it in our RecyclerView.
Go to your RecyclerView Adapter, in our example it’s called Social_RVAdapter, and add the following code:
Here’s what we’re doing:
- Create a ViewHolder for our RateView as we have for our Posts (called PostViewHolder) (Line 4 and 6)
- Give a number that we’ll use in the getItemViewType later to know in which row will return our Rate or Post view (Line 9 and 10)
- Give the position we wanna show the RateView in the RecyclerView (Line 12)
- The getItemViewType method will return the RateView in our position that we put in RATE_VIEW_POSITION before (Lines 19-25)
- Set up the layouts for the Rate View and Post View (Lines 30-38)
- Add one more row to include our RateView in our array with our posts (Lines 47)
- Set up our RateView with our preferable prompt text and the colors (Lines 51-58)
- Calculate the position so we don’t skip any Post because from the row that RateView is using (Lines 60-66)
You can find the final project here
If you have any questions feel free to DM me on Twitter @johncodeos or leave a comment below!