Ajuda com ExpandableListView

  • Respostas:1
Helton Reinaldo (HReinaldo Imóveis)
  • Posts no fórum: 4

16/05/2018, 21:47:01 via Web

Olá galera preciso de uma forcinha, estou criando e adaptando um Tipo…

[Pizzas] [Bebidas] [Sobremesas] [Sucos]

Quando eu expandir o cardápio…
[Pizzas]
Calabresa
4Queijos
Frango

[Bebidas]
Coca-cola
Coca 2Litros
Guaraná
Breja

[Sobremesas]
Doce de leite
Pudim
Pavê

[Sucos]
Laranja
Caju
Maracujá

Um Menu Expandable com Categorias e Sub-Categorias vindas do banco de dados Msql

Responder
Helton Reinaldo (HReinaldo Imóveis)
  • Posts no fórum: 4

29/05/2018, 00:46:56 via Web

Olá galera aos trancos e barrancos estou conseguindo criar esse expandable listview, vindo lá do banco
bom vamos ao que consegui até o momento...

private void prepareLista(){
        lstGrupos = new ArrayList<String>();
        lstItensGrupo = new HashMap<String, List<Produto>>();

        StringRequest stringRequest = new StringRequest(Request.Method.GET, URL,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try{
                            JSONArray pro = new JSONArray(response);
                            for(int i = 0; i<pro.length();i++){

                                JSONObject proObj = pro.getJSONObject(i);
                                lstGrupos.add(proObj.getString("categoria"));//Categoria


                                JSONArray itemArray = new JSONArray(response);
                                List<Produto> foods = new ArrayList<>();
                                for(int j=0; j<itemArray.length(); j++){
                                    foods.add(new Produto(proObj.getString("ite"),17.9));
                                }

                                    //List<Produto> foods = new ArrayList<>();//Itens_Da_Categoria
                                    //foods.add(new Produto(proObj.getString("categoria"), 15.5));

                                    lstItensGrupo.put(lstGrupos.get(i),foods);
                            }
                            //cria um adaptador (BaseExpandableListAdapter) com os dados acima
                            listAdapter = new ExpandableListViewAdapter(MainActivity.this, lstGrupos, lstItensGrupo);
                            //define o apadtador do ExpandableListView
                            expListView.setAdapter(listAdapter);
                        }catch (JSONException e){
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
                    }
                });
        Volley.newRequestQueue(this).add(stringRequest);
    }

Bom esta função como estão vendo ela busca os meus dados via Json, as categorias ela esta pegando certinho, porém as Sub-categorias relacionadas a categoria não estou conseguindo pegar. O meu array tbm não ta legal olhem só...

Array
(
    [0] => Array
        (
            [id_categoria] => 1
            [categoria] => Pízzas
            [item] => Array
                (
                    [0] => Array
                        (
                            [categoria_id] => 1
                            [item] => 4 Queijos
                        )

                    [1] => Array
                        (
                            [categoria_id] => 1
                            [item] => Calabresa
                        )

                )

        )

    [1] => Array
        (
            [id_categoria] => 2
            [categoria] => Bebidas
            [item] => Array
                (
                )

        )

    [2] => Array
        (
            [id_categoria] => 3
            [categoria] => Doces
            [item] => Array
                (
                )

        )

    [3] => Array
        (
            [id_categoria] => 4
            [categoria] => Combo
            [item] => Array
                (
                )

        )

)

queria a ajuda de vcs para terminar essa bagaça kkkk

útil?
Responder