Toolbar repeating

Asked

Viewed 60 times

2

Hello, I’m having a problem, my Toolbar is repeating every time I add a new record.

inserir a descrição da imagem aqui

how do I fix it? follows the codes:

public class ListarReportes extends BaseActivity{

Usuario usuario;
RepositorioReporte repositorioReporte;
RecyclerView recyclerView;
ReportListAdapter adapter;

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_listar_reportes);

    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setCustomView(R.layout.teste);
    }
    //Recupera sessao do usuario
    usuario = (Usuario) getIntent().getSerializableExtra("usuario");

    recyclerView = (RecyclerView) findViewById(R.id.rv);
    recyclerView.setHasFixedSize(true);

    LinearLayoutManager llm = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(llm);
    recyclerView.setItemAnimator(new DefaultItemAnimator());

    repositorioReporte = new RepositorioReporte(this);
    List<Reporte> reporte = repositorioReporte.listaQuery(usuario.getId());

    adapter = new ReportListAdapter(reporte);
    recyclerView.setAdapter(adapter);
}

inserir a descrição da imagem aqui

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/rv"
    />

  • Are you sure your Toolbar is not within the layout of your registry? By the way, the layout you posted is weird, it starts with a include and ends with Cardview. This doesn’t even compile.

  • as well within my record?

  • This layout you posted is the R.layout.recycler_view?

  • no, I think it’s a bug of the pq stackoverflow I posted the whole layout and it divided into lol parts

  • Try to edit and place both your Activity layout and your Recycler view layout.

  • Try Now @Androiderson

  • I got it! Thanks to your comment on Recycler view, I realized that Toolbar is for you in the xml of Recycler and not in cardview.

  • Exactly, I wrote in the answer area to close the question.

Show 3 more comments

1 answer

2


As stated in the comments, your Toolbar needs to be in the same XML as your reclycler view. Otherwise it repeats in each item.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.