RecyclerView shows a single data, JSON

0

At the time of showing data only shows only one, this is my database:

When I want to show the supermarket business only the first one appears.

This is the code of the activity:

package com.example.emiliano.myfirstapp;

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.textclassifier.TextLinks;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.example.emiliano.Entidades.negocio;
import com.example.emiliano.adaptador.listanegocioadapter;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class Listanegocio extends AppCompatActivity implements Response.Listener<JSONObject> , Response.ErrorListener {


    private String categoria;
    ProgressDialog progreso;
    RecyclerView recyclernegocio;
    ArrayList<negocio> listanegocio;
    RequestQueue request;
    JsonObjectRequest jsonObjectRequest;

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

        Bundle bundle=getIntent().getExtras();             //RECIBO CATEGORIA DE LOS BOTONES
        categoria = bundle.getString("categoria");


        listanegocio = new ArrayList<>();

        recyclernegocio = (RecyclerView) findViewById(R.id.IdRecycler);
        recyclernegocio.setLayoutManager(new LinearLayoutManager(this));
        recyclernegocio.setHasFixedSize(true);


        request = Volley.newRequestQueue(this);   //aca

        cargarwebservice();

    }

    private void cargarwebservice() {
        progreso = new ProgressDialog(this);   //getappcontext
        progreso.setMessage("Consultando...");
        progreso.show();
        String url = "http://192.168.0.101/DBRemota/wsJSONConsultarNegocio.php?categoria=" + categoria;
        jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,url,null,this,this);
        request.add(jsonObjectRequest);
    }


    @Override
    public void onErrorResponse(VolleyError error) {
        progreso.hide();
        Toast.makeText(this,"No se pudo consultar....." + error.toString(), Toast.LENGTH_LONG).show();
        Log.i("ERROR" , error.toString());
        progreso.hide();
    }

    @Override
    public void onResponse(JSONObject response) {
        negocio negocio=null;

        JSONArray json=response.optJSONArray("negocio");

        try {

            for (int i=0;i<json.length();i++){
                negocio=new negocio();
                JSONObject jsonObject=null;
                jsonObject=json.getJSONObject(i);

                negocio.setNombre(jsonObject.optString("nombre"));  //NOMBRE DEL ARCHIVO PHP
                negocio.setCategoria(jsonObject.optString("categoria"));
                negocio.setDescripcion(jsonObject.optString("descripcion"));

                listanegocio.add(negocio);
                Toast.makeText(this,"-"  ,Toast.LENGTH_LONG).show();
            }
            progreso.hide();
            listanegocioadapter adapter=new listanegocioadapter(listanegocio);   //CREAR RECYCLER
            recyclernegocio.setAdapter(adapter);

        } catch (JSONException e) {
            e.printStackTrace();
            Toast.makeText(this, "No se ha podido establecer conexión con el servidor" +
                    " "+response, Toast.LENGTH_LONG).show();
            progreso.hide();
        }


    }
}

This is the logcat, I press supermarket at the same time:

and the result:

    
asked by Ibarra Emiliano 25.11.2018 в 22:26
source

0 answers