![]() |
VOOZH | about |
This is the Part 7 of "Build a Social Media App in Android Studio" tutorial, and we are going to cover the following functionalities in this article:
Step 1: Create a Logout and Search Button in the menu folder
Go to the app > res > menu > right-click > New > Menu Resource File and name the file as main_menu. Below is the code for the main_menu.xml file.
Step 2: Working with the HomeFragment.java file
We are searching for a blog in Node "Posts" using title and description value. If any key-value matches then it will all those blogs whose value contains our search content
if(modelPost.getTitle().toLowerCase().contains(search.toLowerCase())||
modelPost.getDescription().toLowerCase().contains(search.toLowerCase())) {
posts.add(modelPost);
}
Below is the code for the Logout functionality
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.logout) {
firebaseAuth.signOut();
startActivity(new Intent(getContext(), SplashScreen.class));
getActivity().finish();
}
return super.onOptionsItemSelected(item);
}
Go to the HomeFragment.java file and refer to the following code. Below is the complete and updated code for the HomeFragment.java file.
Note: Please Add drawable items before running the Application
Below is the file structure after performing these operations:
👁 Image