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);
This can be achieved by resorting to a Expandablelistview. Look at this reply for an example.
– ramaral