Several recycle views in same activty

0

Does anyone know how to create multiple lists (Recycleview) in the same activty according to the data in the database? 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.

    
asked by anonymous 12.05.2016 / 15:11

1 answer

0

If you are creating an application, I would not advise you to put more than Recycleview on the screen. Try to show in a Recycleview categories and as soon as the user chooses the category, you show in another screen the Recycleview containing the items of that category. There is a way for you to pick up the selected item and assign its values to 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 is already saved. At the next activity , retrieve the data as follows:

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

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

 filial.setAdapter(adapter);
    
12.05.2016 / 15:29