Multiple Recycle views on the same activty

Asked

Viewed 56 times

0

does anyone know how to create multiple lists (Recycleview) on the same activty according to the database data? That is, I have a table called Categories and another table of Items, I wanted to create a list for each category containing the items in that category.

1 answer

0

If you are creating an app, I wouldn’t advise you to put more than one Recycleview on screen. Try to show in a Recycleview the categories and as soon as the user choose the category, you show in another screen the Recycleview containing items from that category.
There is a way for you to pick up the selected item and assign its values on another screen. follows an example:

    Log.i("QTDE de itens", "" + lista.size());
            if(lista.size()>0) {
                ltsunidades = (ListView) findViewById(R.id.ltsunidades);

                final ArrayAdapter<Tab_UC> adapter = new ArrayAdapter<Tab_UC>
                        (Selecionar_Unidade.this, R.layout.list_item_text2, lista);
                ltsunidades.setAdapter(adapter);

            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(
                        Selecionar_Unidade.this)
                        .setTitle("Erro")
                        .setMessage("Não foi possível acessar as informações!!")
                        .setPositiveButton("OK", null);
                builder.create().show();
            }

            //selecionando unidade
            ltsunidades.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView adapter, View view, int posicao, long id) {
                    Tab_UC obj = (Tab_UC) adapter.getItemAtPosition(posicao);
                    String filial = "" + obj.getCod_UC();
nesta String filial eu atribuo o objeto selecionado  porem no meu caso apenas o Cod_UC da tabela   para você   pode ser o obj inteiro. ficaria assim:
                       String filial = "" + obj;

                    Intent it = new Intent(getBaseContext(), Empresa.class);
                    it.putExtra("Filial", filial);
                    startActivity(it);
                    // Toast.makeText(getApplicationContext(), " " + filial, Toast.LENGTH_SHORT).show();

                }
            });

When you open the new Intent, the object selected by the user will already be saved. In the next activity, recover the data as follows:

 String filial = getIntent().getExtras().getString("Filial");

Now just use this variable, branch (in my case) and set it in your Recycleview as follows:

 filial.setAdapter(adapter);
  • I wanted to do something similar to the home page of Youtube where I realize that each channel is a different list, but I think for now I will use two same activtys. Thank you so much for your time.

  • You’re welcome!!

Browser other questions tagged

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