Store multiple nodes to Firebase Realtime Database - java

I'm new to using Firebase and Android Studio and I need multiple nodes to save to a realtime database in Firebase from my android app, these include users, budgets and spending as it's an expense tracking app. I've got the user information to save under its own node but I can't figure out how to create nodes for budget and spending. The code below is what I'm having difficulty with :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_categories);
setupUIViews();
firebaseAuth = getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
btn_subCat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(validate()){
sendUserBudgets();
Toast.makeText(Categories.this, "Completed!", Toast.LENGTH_LONG).show();
finish();
startActivity(new Intent(Categories.this, Menu.class ));
}else{
Toast.makeText(Categories.this, "Submission failed", Toast.LENGTH_LONG).show();
}
}
});
}
private void setupUIViews() {
travel_input = (EditText)findViewById(R.id.travel_input);
entertainment_input = (EditText)findViewById(R.id.entertainment_input);
fitness_input = (EditText)findViewById(R.id.fitness_input);
beauty_input = (EditText)findViewById(R.id.beauty_input);
clothes_input = (EditText)findViewById(R.id.clothes_input);
holiday_input = (EditText)findViewById(R.id.holiday_input);
food_input = (EditText)findViewById(R.id.food_input);
mobile_input = (EditText)findViewById(R.id.mobile_input);
btn_subCat = (Button)findViewById(R.id.btn_subCat);
}
private Boolean validate() {
boolean result = false;
travel_budget = Double.parseDouble(travel_input.getText().toString().trim());
entertainment_budget = Double.parseDouble(entertainment_input.getText().toString().trim());
fitness_budget = Double.parseDouble(fitness_input.getText().toString().trim());
beauty_budget = Double.parseDouble(beauty_input.getText().toString().trim());
clothes_budget = Double.parseDouble(clothes_input.getText().toString().trim());
holiday_budget = Double.parseDouble(holiday_input.getText().toString().trim());
food_budget = Double.parseDouble(food_input.getText().toString().trim());
mobile_budget = Double.parseDouble(mobile_input.getText().toString().trim());
if(travel_budget.equals(null) || entertainment_budget.equals(null) || fitness_budget.equals(null) || beauty_budget.equals(null) || clothes_budget.equals(null) || holiday_budget.equals(null) || food_budget.equals(null) ||
mobile_budget.equals(null)){
Toast.makeText(Categories.this, "Please enter all fields", Toast.LENGTH_LONG).show();
} else {
result = true;
}
return result;
}
private void sendUserBudgets() {
String currentUserID = firebaseAuth.getUid();
CategoriesDB catDb = new CategoriesDB(travel_budget, entertainment_budget, fitness_budget, beauty_budget, clothes_budget, holiday_budget, food_budget, mobile_budget);
mDatabase.child("User").child(currentUserID).child("Budgets").setValue(catDb);
}

private void validate() {
boolean result = false;
travel_budget = Double.parseDouble(travel_input.getText().toString().trim());
entertainment_budget = Double.parseDouble(entertainment_input.getText().toString().trim());
fitness_budget = Double.parseDouble(fitness_input.getText().toString().trim());
beauty_budget = Double.parseDouble(beauty_input.getText().toString().trim());
clothes_budget = Double.parseDouble(clothes_input.getText().toString().trim());
holiday_budget = Double.parseDouble(holiday_input.getText().toString().trim());
food_budget = Double.parseDouble(food_input.getText().toString().trim());
mobile_budget = Double.parseDouble(mobile_input.getText().toString().trim());
if(travel_budget.equals(null) || entertainment_budget.equals(null) || fitness_budget.equals(null) || beauty_budget.equals(null) || clothes_budget.equals(null) || holiday_budget.equals(null) || food_budget.equals(null) ||
mobile_budget.equals(null)){
Toast.makeText(Categories.this, "Please enter all fields", Toast.LENGTH_LONG).show();
} else {
sendUserBudgets(travel_budget, fitness_budget, beauty_budget, clothes_budget, holiday_budget, food_budget, mobile_budget);
}
}
private void sendUserBudgets(double travel_budget, double fitness_budget, double beauty_budget, double clothes_budget, double holiday_budget, doublefood_budget, double mobile_budget) {
String currentUserID = firebaseAuth.getUid();
CategoriesDB catDb = new CategoriesDB(travel_budget, entertainment_budget, fitness_budget, beauty_budget, clothes_budget, holiday_budget, food_budget, mobile_budget);
mDatabase.child("User").child(currentUserID).child("Budgets").setValue(catDb);
}
Here once you have obtained all the user inputs and have done all the validations, you need to call the function sendUserBudgets() to save it to the database.

Related

How can i change the value of a TextView Instantly, as i push the update button that retrieves data from a Database?

public class UserprofileActivity extends AppCompatActivity {
// VARIABLES
TextView fullName, userName, location, motorcycle;
TextInputLayout fullNameInput, emailInput, motorcycleInput, passwordInput;
// GLOBAL VARIABLES TO HOLD USER DATA INSIDE THIS ACTIVITY
String _NAME, _USERNAME, _EMAIL, _LOCATION, _MOTORCYCLE, _PASSWORD;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_userprofile);
reference = FirebaseDatabase.getInstance().getReference("users");
// HOOKS
fullName = findViewById(R.id.profileFullName);
userName = findViewById(R.id.profileUsername);
location = findViewById(R.id.profileLocalization);
motorcycle = findViewById(R.id.profileMotorcycle);
fullNameInput = findViewById(R.id.profile_FullName);
emailInput = findViewById(R.id.profile_Email);
motorcycleInput = findViewById(R.id.profile_Motorcycle);
passwordInput = findViewById(R.id.profile_Password);
// SHOW ALL DATA
showAllUserData();
}
private void showAllUserData() {
Intent intent = getIntent();
_NAME = intent.getStringExtra("name");
_USERNAME = intent.getStringExtra("username");
_EMAIL = intent.getStringExtra("email");
_LOCATION = intent.getStringExtra("location");
_MOTORCYCLE = intent.getStringExtra("motorcycle");
_PASSWORD = intent.getStringExtra("password");
// this variable goes to (TextInputLayout "fullNameInput) and (TextView fullName) this goes to update the full name of the user and also is motorcycle brand. It should update both TextViews(Full Name and Motorcycle) with the data retrieved from the database at the same time and as soon as i would click the update button below the form. But it only updates after a new login. (The table name of the Database is users and the first child is the Username). enter image description here
fullName.setText(_NAME);
userName.setText(_USERNAME);
location.setText(_LOCATION);
motorcycle.setText(_MOTORCYCLE);
Objects.requireNonNull(fullNameInput.getEditText()).setText(_NAME);
Objects.requireNonNull(emailInput.getEditText()).setText(_EMAIL);
Objects.requireNonNull(motorcycleInput.getEditText()).setText(_MOTORCYCLE);
Objects.requireNonNull(passwordInput.getEditText()).setText(_PASSWORD);
}
private boolean isNameChanged() {
if (!_NAME.equals(Objects.requireNonNull(fullNameInput.getEditText()).getText().toString())) {
reference.child(_USERNAME).child("name").setValue(fullNameInput.getEditText().getText().toString());
fullName.getText().equals(_NAME);
return true;
} else {
return false;
}
}
private boolean isMotorcycleChanged() {
if (!_MOTORCYCLE.equals(Objects.requireNonNull(motorcycleInput.getEditText()).getText().toString())) {
reference.child(_USERNAME).child("motorcycle").setValue(motorcycleInput.getEditText().getText().toString());
return true;
} else {
return false;
}
}
public void update(View view) {
if (isNameChanged() || isEmailChanged() || isMotorcycleChanged() || isPasswordChanged()) {
Toast.makeText(this, "Data has been Updated Successfully", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Data is the Same and therefore Cannot be Updated", Toast.LENGTH_LONG).show();
}
}
}

Unable to use boolean values in IF statements

I have a database that is being checked using a Cursor. This database compares the data in the database to the user entered username and password. If they match data in the database a boolean is returned true. I can use a toast to output the boolean which correctly outputs as true or false if the input data does or does not match.
However, i am trying to use the boolean to move to the next activity. If the boolean is true the next intent is started. This does not work for some reason and I cant seem to work out why. Any help would be great. Thanks!
public Button btnLogin, btnSignup;
public EditText UsernameInput, PasswordInput;
public DatabaseHelper db;
public static String passUser, passPass, passFirst, passSecond;
public int count;
public Boolean matchingUser = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Align page and remove notification bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// Define everything
btnLogin = findViewById(R.id.btnLogin);
btnSignup = findViewById(R.id.btnSignup);
UsernameInput = findViewById(R.id.UsernameInput);
PasswordInput = findViewById(R.id.PasswordInput);
db = new DatabaseHelper(this);
// validation button
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
validateLogin(UsernameInput.getText().toString(), PasswordInput.getText().toString());
}
});
btnSignup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CreateUser();
}
});
}
// Validation code
public void validateLogin(String userName, String userPassword)
{
if (userName.equals("")|| userPassword.equals(""))
{
Toast.makeText(getApplicationContext(),"Fields are empty",Toast.LENGTH_SHORT).show();
}
else
{
// CHECKING USER LOGIN DETAILS
Cursor cursor = db.CompareUserData();
for (count = 0; count<=cursor.getCount();count++)
{
if (cursor.moveToPosition(count))
{
if (UsernameInput.getText().toString().equals(cursor.getString(0))&&PasswordInput.getText().toString().equals(cursor.getString(1)))
{
matchingUser = true;
}
}
Toast.makeText(this, "boolean : "+ matchingUser, Toast.LENGTH_SHORT).show();
if (matchingUser = true)
{
passUser = cursor.getString(0);
passPass = cursor.getString(1);
passFirst = cursor.getString(2);
passSecond = cursor.getString(3);
getUser();
getPass();
getFirst();
getSecond();
Toast.makeText(getApplicationContext(), "Successfully logged in", Toast.LENGTH_SHORT).show();
LoginValidation();
}
if (matchingUser = false)
{
Toast.makeText(getApplicationContext(),"Incorrect Username",Toast.LENGTH_SHORT).show();
}}
}
}
private void LoginValidation()
{
// Changing activity code
startActivity(new Intent(MainActivity.this,Login_Biometrics.class));
}
private void CreateUser()
{
// Changing activity code
startActivity(new Intent(MainActivity.this,createUser.class));
}
public static String getUser ()
{
return passUser;
}
public static String getPass ()
{
return passPass;
}
public static String getFirst ()
{
return passFirst;
}
public static String getSecond ()
{
return passSecond;
}
It wont work with one = equal sign just do:
if(matchingUser) {
// if true do something
} else {
// if false do something
}
In your case:
if (matchingUser) {
passUser = cursor.getString(0);
passPass = cursor.getString(1);
passFirst = cursor.getString(2);
passSecond = cursor.getString(3);
getUser();
getPass();
getFirst();
getSecond();
Toast.makeText(getApplicationContext(), "Successfully logged in",Toast.LENGTH_SHORT).show();
LoginValidation();
} else {
Toast.makeText(getApplicationContext(),"Incorrect Username",Toast.LENGTH_SHORT).show();
}
You have to understand some basics:
Assignment operator =
Is used to assign value to some variable.
Logical operator ==
Is used to make some logical comparison.
So instead of doing this:
if (matchingUser = true)
{
...
Do this
if (matchingUser == true)
{
...
Apply this for every condition checking in your code.

How to change data in firebase and check id auto increment

Hye, my problem is to rewrite if the user put the same nameItem that will change the price and the quantityItem, if not the item will add new id. i also do auto increment on id.
My Database :
This is how i try but when the name == nameItem can't read and run on else in on DataChange.
if(i != 0){
for(id1 = 1; id1<=i; id1++){
if(id1 != 0){
final DatabaseReference reff1 = FirebaseDatabase.getInstance().getReference().child("CartList").child(userID).child(String.valueOf(id1));
reff1.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
String carinama = dataSnapshot.child("nameItem").getValue().toString();
String changequantity = dataSnapshot.child("quantityItem").getValue().toString();
if(nameItem == carinama) {
int calcQuantity = Integer.parseInt(cdtb.getQuantityItem());
newpositionItem = newpositionItem + calcQuantity;
String x = String.valueOf(newpositionItem);
cdtb.setQuantityItem(x);
int price1Item = Integer.parseInt(priceItem);
newpositionItem = newpositionItem * price1Item;
cdtb.setPriceItem(d2f.format(newpositionItem));
reff1.setValue(cdtb);
id1 = i;
}else {
int calcQuantity = Integer.parseInt(changequantity);
newpositionItem = newpositionItem + calcQuantity;
String x = String.valueOf(newpositionItem);
cdtb.setQuantityItem(x);
double price1Item = Double.parseDouble(priceItem);
newpositionItem = newpositionItem * price1Item;
cdtb.setPriceItem(d2f.format(newpositionItem));
reff1.setValue(cdtb);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(getContext(), ""+databaseError, Toast.LENGTH_SHORT).show();
}
});
}else {
}
}
}else{
cdtb.setImageItem(imageUrl);
cdtb.setNameItem(nameItem);
cdtb.setPriceItem(d2f.format(calcPrice));
cdtb.setSpecification(specItem);
cdtb.setQuantityItem(positionItem);
reff.child(String.valueOf(++maxid)).setValue(cdtb);
}
Thank you...
nameItem and carinama is String
in java to compare two string you must use equals method not "=="
because == will compare object location in memory and not the content string
so you code condition will be
if(nameItem.equals(carinama)){
//your code here
}

TextView with data from firebase rt dababase disappear on screen

I'm trying to get a user name from the database and set it as text on the screen.
I have 3 Activity and Fragment objects.
The first activity is RegisterActivity. After the user inserts his email and password, and clicks the next button, a pop up with input fields for user details appears.
Users should fill all fields and click the save button.
For the OnClick action of the save button, all users details are written to a real time database.
In the main Activity, I want to show the user name from the database.
In debug mode, I get the user name, but it won't show on the TextView (private TextView mWelcomeText).
Here is what I've done:
package com.enjoyapp.weddapp.Activities;
public class MainActivity extends AppCompatActivity {
private TextView mWelcomeText;
private String mGreetings;
private String mDisplayName;
private FirebaseAuth mAuth;
private FirebaseDatabase db;
private DatabaseReference users;
private MethodManager mm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
db = FirebaseDatabase.getInstance();
users = db.getReference("Users");
mWelcomeText = findViewById(R.id.mWelcomeText);
bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(navListener);
getDataFromUsersDetails();
mWelcomeText.setText(mDisplayName);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment())
.commit();
}
private BottomNavigationView.OnNavigationItemSelectedListener navListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
Fragment selectedFragment = null;
switch (menuItem.getItemId()) {
case R.id.nav_home:
selectedFragment = new HomeFragment();
break;
case R.id.nav_favorites:
selectedFragment = new FavoritesFragment();
break;
case R.id.nav_search:
selectedFragment = new SearchFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, selectedFragment)
.commit();
return true;
}
};
public void getDataFromUsersDetails() {
ValueEventListener eventListener = new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
mDisplayName = ds.child(mAuth.getCurrentUser().getUid()).child("mEventOwnerName").getValue(String.class);
Log.d("Database reader", mDisplayName);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
};
users.addListenerForSingleValueEvent(eventListener);
}
public String getGreetings() {
mm = new MethodManager();
if (mm.getTime() >= 6 && mm.getTime() < 12) {
return "Good morning";
} else if (mm.getTime() >= 12 && mm.getTime() < 18) {
return "Good afternoon";
} else if (mm.getTime() >= 18 && mm.getTime() < 22) {
return "Good evening";
} else if (mm.getTime() >= 22 && mm.getTime() < 6) {
return "Good night";
}
return null;
}
}
I want the text to be displayed on the screen, in the field of private TextView mWelcomeText.
In the layout_main I can see the text view with the tool:text="something";
But when I am running it on a real device or an emulator, just an empty place appears.
UPDATE:
public void getDataFromUsersDetails() {
ValueEventListener eventListener = new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
mDisplayName = ds.child(mAuth.getCurrentUser().getUid()).child("mEventOwnerName").getValue(String.class);
Log.d("Database reader", mDisplayName);
user = new User();
user.setmDisplayName(mDisplayName);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
};
users.addListenerForSingleValueEvent(eventListener);
}
mWelcomeText = findViewById(R.id.mWelcomeText);
mWelcomeText.setText(user.setGreetingsOnTop());
public String setGreetingsOnTop(){
MethodManager mm = new MethodManager();
String greetings = null;
if (mm.getTime() >= 6 && mm.getTime() < 12) {
greetings = "Good morning";
} else if (mm.getTime() >= 12 && mm.getTime() < 18) {
greetings = "Good afternoon";
} else if (mm.getTime() >= 18 && mm.getTime() < 22) {
greetings = "Good evening";
} else if (mm.getTime() >= 22 && mm.getTime() < 6) {
greetings = "Good night";
}
return getmDisplayName() +""+greetings;
}
I would request you take a look on this two line of Main Activity.
getDataFromUsersDetails();
mWelcomeText.setText(mDisplayName); //mDisplayName is null initially
getDataFromUsersDetails is making an asynchronous call using valueEventListener. When the response is coming you are assigning the value to mDisplayName but it will not update in textView.
In the For loop you need to explicitly update mWelcomeText.setText(mDisplayName);
You can must update the textview inside the valueEventListener
for (DataSnapshot ds : dataSnapshot.getChildren()) {
mDisplayName = ds.child(mAuth.getCurrentUser().getUid()).child("mEventOwnerName").getValue(String.class);
Log.d("Database reader", mDisplayName);
mWelcomeText.setText(mDisplayName);//here
}

Trying to save the state of a toggle Button and make visible some view depending on it

I have a switch that when you click it it populates a RecyclerView and trying to save the state through the lifecycle.
This is the xml
<Switch
android:id="#+id/reviewLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/eight_dp"
android:textColor="#android:color/white" />
This is the listener
private class ShowReviewsListener implements CompoundButton.OnCheckedChangeListener{
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if(isChecked == true){
showReviews();
isReviewButtonClicked = true;
}else if(isChecked == false){
isReviewButtonClicked = false;
}
}
}
This is what happens when you click it
public void showReviews() {
mReviewList.setHasFixedSize(true);
mReviewList.setVisibility(View.VISIBLE);
fakeView2.setVisibility(View.VISIBLE);
}
This is how i try to save it and retrieve it
#Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt(INSTANCE_MOVIE_ID, mMovieId);
outState.putBoolean(IS_IN_FAVORITES, isInFavsAlready);
outState.putBoolean(REVIEW_BUTTON, isReviewButtonClicked);
super.onSaveInstanceState(outState);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_detail);
mDb = AppDatabase.getInstance(getApplicationContext());
mToolbar = findViewById(R.id.toolbar);
mToolbar.setTitle(R.string.movie_details_title);
ButterKnife.bind(this);
if (savedInstanceState != null && savedInstanceState.containsKey(INSTANCE_MOVIE_ID)) {
mMovieId = savedInstanceState.getInt(INSTANCE_MOVIE_ID, DEFAULT_MOVIE_ID);
}
if(savedInstanceState !=null && savedInstanceState.containsKey(IS_IN_FAVORITES)){
isInFavsAlready = savedInstanceState.getBoolean(IS_IN_FAVORITES, false);
}
if(savedInstanceState !=null && savedInstanceState.containsKey(REVIEW_BUTTON)){
isReviewButtonClicked = savedInstanceState.getBoolean(REVIEW_BUTTON, false);
}
Log.d(LOG_TAG, "review button " + isReviewButtonClicked);
Intent i = getIntent();
if (i != null && i.hasExtra(EXTRA_MOVIE)) {
if (mMovieId == DEFAULT_MOVIE_ID) {
mMovieId = i.getIntExtra(EXTRA_MOVIE, DEFAULT_MOVIE_ID);
mMovie = i.getParcelableExtra(EXTRA_MOVIE);
populateUI(mMovie);
}
}
setTrailers();
setReviews();
if (isReviewButtonClicked) {
showReviews();
}
int movieID = Integer.parseInt(mMovie.getMovieId());
isMovieInFavorites(movieID);
reviewSwitch.setOnCheckedChangeListener(new ShowReviewsListener());
favoriteToggle.setOnCheckedChangeListener(new FavoriteListener());
}
Right now even though the isChecked is true, whenever i rotate the device, the views from showReviews() are staying hidden.
EDIT: Added full onCreate & image
Reviews handle
private class FetchReviewsAndTrailersTask extends AsyncTask<URL, Void, String[]> {
#Override
protected String[] doInBackground(URL... urls) {
URL searchReviewUrl = NetworkUtils.createReviewsUrl(mMovie.getMovieId());
URL searchVideoUrl = NetworkUtils.createVideosUrl(mMovie.getMovieId());
String jsonReviewString = "";
String jsonVideoString = "";
try {
jsonReviewString = NetworkUtils.makeHttpRequest(searchReviewUrl);
jsonVideoString = NetworkUtils.makeHttpRequest(searchVideoUrl);
} catch (IOException e) {
Log.e("Main Activity", "Problem making the HTTP request.", e);
}
return new String[]{jsonVideoString, jsonReviewString};
}
#Override
protected void onPostExecute(String[] jsonString) {
if (jsonString == null) {
fakeView.setVisibility(View.VISIBLE);
}
mTrailers = JsonUtils.extractTrailersFromJson(jsonString[0]);
mReviews = JsonUtils.extractReviewsFromJson(jsonString[1]);
populateReviewsAndTrailers(mReviews, mTrailers);
}
}
private void populateReviewsAndTrailers(List<Review> review, List<Trailer> trailers){
if (review.isEmpty()) {
reviewSwitch.setText(R.string.reviewLabelNone);
} else {
reviewSwitch.setText(R.string.reviewLabelExist);
fakeView.setVisibility(View.GONE);
mAdapter = new MovieReviewsRecyclerViewAdapter(MovieDetailActivity.this, mReviews);
mReviewList.addItemDecoration(new DividerItemDecoration(getApplicationContext(), DividerItemDecoration.VERTICAL));
mReviewList.setAdapter(mAdapter);
mReviewList.setVisibility(View.GONE);
}
if(trailers.isEmpty()){
trailersHeader.setText(R.string.trailersNA);
}else{
trailersHeader.setText(R.string.trailerHeader);
mTrailerAdapter = new MovieTrailersRecyclerViewAdapter(MovieDetailActivity.this, mTrailers);
mTrailersList.setAdapter(mTrailerAdapter);
}
}
I guess you forget to show reviews after rotating screen.
Try this:
if(savedInstanceState !=null && savedInstanceState.containsKey(REVIEW_BUTTON)){
isReviewButtonClicked = savedInstanceState.getBoolean(REVIEW_BUTTON, false);
if (isReviewButtonClicked) showReviews();
}

Categories