Skip to main content

How to add a user list to your social media app

 

Sable App User List



The user list will provide a list of all our users. Depending on the size of your network, your user list may range from a few people to millions. The user list is important because it shows a new or existing user who else is using the app and it allows them an opportunity to connect.

This tutorial will cover how to create a userlist for your app. The user list will look similar to the one shown in the image above.

As you get more experienced, we will optimise our app to perform better and cater for larger audiences.

Create the layout

Create a new Activity. Give this activity a new name... something like "users", "allusers" or "students". This will depend on the type of app. 



Add a linear Horizontal


Inside the linear Horizontal, place an imageview, a textview and an imageview inside the linear. Give the textview a weight of 1. This will make it take up the entire screen.

Change the imageviews and place the icons you want to use. In my example, I am using a search image and a back image.

Under the linear, place a listview. It should look similar to the one shown in the image above.

Add a customview





I have named my customview 'userlist'. You can give yours any name... just remember to follow the corresponding steps


Create the layout for how you want your list to be displayed.

I did this by adding a linear Horizontal.

Inside the linear Horizontal I placed an imageview.

I placed a linear vertical, next to the imageview (inside the linear Horizontal).

Inside the linear vertical I placed 3 textviews. I made the first one bold. This will hold the username.

My layout will look as shown below. Please note that I changed the text and the imageview in the properties.




Connect your customview to your listview

First click on the listview widget to reveal the properties menu. In the properties menu, select custom view as shown below


Select the specific customview that you want to display the user list. 





Create a firebase db component

Navigate to the components section of your app as shown below



Click the red button similar to the one in the image below to create a new component


The components menu will be revealed. Click the 'firebase DB' component.



Name your firebase component.

Since we want to retrieve data that the user will have added in the profile section to the location users/userprofile, we will recreate the same component. You can name your component whatever you want... just remember to recreate the same component and file name in the different sections.



Navigate to the onChildAdded






Create a listmap as shown below.





In my example I've given my listmap the name userprof. You can give yours any name.




Add the following blocks Onchildadded to retrieve all the user data from your firebase DB directory users/userprofile. This logic will get the data from Firebase and display it in your listview


On child added logic


OnbindCustomview

Navigate to the OnbindCustomview view event by following the steps shown below




Place the following blocks OnbindCustomview to determine which data will be displayed. I will show you two ways of displaying data. The first is simple and the second is slightly more complex.

Method 1


This method will display data and will work if you assign data to each user when they create an account. 


This method might cause our app to crash if the user has not completed their profile. A lot of users will create profiles and leave them incomplete. Thus to avoid them we will use the following method.

Method 2 (Recommended)


This method uses some block to check if the listmap contains a key with a particular value at a specific position of the list. If that key is empty, we then assign a value to it. So the logic for a single block will be as follows:


So our logic will look as shown below



You can run your app to check out your user list.



Comments

Popular posts from this blog

Hip hop and RnB songs to apologize to your partner

Love is a beautiful thing, but it often goes wrong. This often leads to pain, suffering and sorrow.  Being imperfect beings, hearts tend to get broken all the time regardless how hard we may try to avoid it.  The heartbreak is often inadvertent but at times we find ourselves in the wrong. An oversight, a word unsaid or even a lapse in our judgement can cause our loved ones harm. This doesn't always have to be the end though. Oftentimes, relationships can be mended by simply uttering three simple words: "I AM SORRY". This article is a collection of some of my favourite 'I'm sorry' songs. I hope you'll enjoy these apology songs, but more importantly, I hope you will get a few quotables and some wisdom nuggets from them.  The best apology however, is to change behaviour (got that from a Jay Z interview) so as you apologize, please remember that it was your actions that hurt them. The best apology is one which involves you not repeating those same mistakes aga

Php date: How to get the first and last day of the week

In this tutorial, I'll show you how to get the first and last day of the week in php. By default, in PHP the week runs from Monday to Sunday. However we'll cover two methods to get the first and last day for both those who consider Sunday or Monday as their first day of the week. We will be using 2 functions to achieve this: date() strtotime() We will use a combination of these two functions and store the result in a variable.  How to get the first day of the week If you want to get Sunday, use this method: $firstday = date('l Y-m-d', strtotime("sunday -1 week")); echo $firstday; If you want to get the date for Monday, this current week, use this method: $monday = date('l Y-m-d', strtotime("monday -1 week ")); echo $monday; How to get the last day of the week The following code will give you Saturday as the last day of the current week. $lastday = date('l Y-m-d', strtotime("saturday 0 week")); echo $last

How to easily create background notifications in Sketchware(original)

How to easily create background notifications in Sketchware(original) One of the keys to building a successful app is to find mechanisms that will keep your users engaged. You can do this by using background notifications. This tutorial will show you how to do that in Sketchware. We will cover: 1. How to create notifications in Sketchware 2. How to show these notifications even when the app is closed.