i have appbar configuration problem could any one help me please?

Chaymae Benayyad 21 Reputation points
2021-12-08T13:26:48.497+00:00

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Menu;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;

import com.example.shopingonline.Model.Products;
import com.example.shopingonline.Model.Users;
import com.example.shopingonline.Prevalent.Prevalent;
import com.example.shopingonline.ViewHolder.ProductViewHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.navigation.NavigationView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.core.view.GravityCompat;
import androidx.customview.widget.Openable;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shopingonline.databinding.ActivityHomeBinding;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;
import io.paperdb.Paper;

public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

private AppBarConfiguration mAppBarConfiguration;

private DatabaseReference ProductsRef;  
private RecyclerView recyclerView;  
RecyclerView.LayoutManager layoutManager;  


@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.activity_home);  

    ProductsRef = FirebaseDatabase.getInstance().getReference().child("Products");  



    Paper.init(this);  
    Toolbar toolbar = findViewById(R.id.toolbar);  
    toolbar.setTitle("Home");  
    setSupportActionBar(toolbar);  

    FloatingActionButton fab = findViewById(R.id.fab);  
    fab.setOnClickListener(new View.OnClickListener() {  
        @Override  
        public void onClick(View view) {  
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)  
                    .setAction("Action", null).show();  
        }  
    });  

    DrawerLayout drawer = findViewById(R.id.drawer_layout);  


    NavigationView navigationView = findViewById(R.id.nav_view);  

    View headerView = navigationView.getHeaderView(0);  
    TextView userNameTextView = headerView.findViewById(R.id.user_profile_name);  
    CircleImageView profileImageView = headerView.findViewById(R.id.user_profile_image);  
    userNameTextView.setText(Prevalent.currentOnlineUser.getName());  



    // Passing each menu ID as a set of Ids because each  
    // menu should be considered as top level destinations.  
    mAppBarConfiguration = new AppBarConfiguration.Builder(  
            R.id.nav_cart, R.id.nav_categories, R.id.nav_logout,R.id.nav_settings, R.id.nav_orders, R.id.nav_home)  
            .setOpenableLayout(drawer)  
            .build();  
    //NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_home);  
    //NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);  
    //NavigationUI.setupWithNavController(navigationView, navController);  

    recyclerView = findViewById(R.id.recycler_menu);  
    recyclerView.setHasFixedSize(true);  
    layoutManager = new LinearLayoutManager(this);  
    recyclerView.setLayoutManager(layoutManager);  
}  


@Override  
protected void onStart() {  
    super.onStart();  

    FirebaseRecyclerOptions<Products> options =  
            new FirebaseRecyclerOptions.Builder<Products>()  
            .setQuery(ProductsRef,Products.class)  
            .build();  

    FirebaseRecyclerAdapter<Products, ProductViewHolder> adapter =  
            new FirebaseRecyclerAdapter<Products, ProductViewHolder>(options) {  
                @Override  
                protected void onBindViewHolder(@NonNull ProductViewHolder holder, int position, @NonNull Products model) {  

                    holder.txtProductName.setText(model.getPname());  
                    holder.txtProductDescription.setText(model.getDescription());  
                    holder.txtProductPrice.setText("Price = "+ model.getPrice());  
                    Picasso.get().load(model.getImage()).into(holder.imageView);  


                }  

                @NonNull  
                @Override  
                public ProductViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {  
                    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.product_items_layout, parent, false);  
                    ProductViewHolder holder = new ProductViewHolder(v);  
                    return holder;  
                }  
            };  
        recyclerView.setAdapter(adapter);  
        adapter.startListening();  

}  

@Override  
public boolean onCreateOptionsMenu(Menu menu) {  
    // Inflate the menu; this adds items to the action bar if it is present.  
    getMenuInflater().inflate(R.menu.home, menu);  
    return true;  
}  

//@Override  
//public boolean onSupportNavigateUp() {  
    //NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_home);  
    //return NavigationUI.navigateUp(navController, mAppBarConfiguration)  
            //|| super.onSupportNavigateUp();  

// }

@Override  
public boolean onOptionsItemSelected(MenuItem item){  
    int id = item.getItemId();  




    return super.onOptionsItemSelected(item);  
}  

@SuppressWarnings("StatementWithEmptyBody")  

@Override  
public boolean onNavigationItemSelected(MenuItem item) {  
    int id = item.getItemId();  
    if (id == R.id.nav_cart) {  

    } else if (id == R.id.nav_orders) {  

    } else if (id == R.id.nav_categories) {  
    } else if (id == R.id.nav_settings) {  
        Intent intent = new Intent(HomeActivity.this,settinsActivity.class);  
        startActivity(intent);  
    } else if (id == R.id.nav_logout) {  
        Paper.book().destroy();  

        Intent intent = new Intent(HomeActivity.this,MainActivity.class);  
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);  
        startActivity(intent);  
        finish();  
    }  

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);  
    drawer.closeDrawer(GravityCompat.START);  
    return true;  
}  

}155946-xfgfgddfgh.png

this is the image and the code of the HomeActivity.java actually i'm doing a tutorial and i found some difficult because of the new version of android studio i add an Intent as you see in the onNavigationItemSelected(MenuItem item) methode to go to another activity but it doesn't work when i click in the button of the bar like logout or settings can you help me to found the problem please Thanks

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,794 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Alessandro Caliaro 4,181 Reputation points
    2021-12-08T13:47:11.22+00:00

    This seems to be java code.. I think you have posted to a wrong forum

    0 comments No comments

  2. Chaymae Benayyad 21 Reputation points
    2021-12-08T13:48:31.347+00:00

    what i should do please

    0 comments No comments