Fill ListView with information loaded in the Firebase database in Json format in Kotlin

0

I have a big problem when trying to bring data from a URL that gives me information in Json format, the application receives this information but at the time of linking the data with a ListView it is a little complicated for me how can I get it if I have 10 objects that offer me some data this becomes a line in the listView and so with each one of those that I have?

This is my MainActivity

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    if (Network.hayred(this)) {
        solicitudHTTPVolley("https://pruebadelistaentiemporeal.firebaseio.com/.json")
    } else {
        //mostrar error)
    }
}


private fun solicitudHTTPVolley(url: String) {
    val queue = Volley.newRequestQueue(this)

    val solicitud = StringRequest(Request.Method.GET, url, com.android.volley.Response.Listener<String> {
        response ->
        Log.d("solicitudHTTPVolley", response)

        //En revision
        /val gson = Gson()
        val VIGAS = gson.fromJson(response, FirebaseRequest::class.java)
        Log.d("PLANOS", VIGAS.ListaDEVIGAS?.VIGAS?.size.toString())/

    }, com.android.volley.Response.ErrorListener {

    })
    queue.add(solicitud)
    }
}

What I thought was to create a Gson that tells how many objects contained the list of beams objects (you can see the Json in the URL of the code) and in that way that created as many lines as there are data, if they have a more Simple to do this please let me know. I leave my Adapter, NetWork, Request and the Structure of the data.

class FirebaseRequest {
    var ListaDEVIGAS:Planos? = null
}

    class Planos{
        var VIGAS:ArrayList<InfoPlano>? = null
}
    class  InfoPlano{
       var Plano:String = ""
       var Cantidad:Int = 0
       var Codigo:String = ""
       var Detalle:String = ""
       var Obra:String = ""
       var Peso:Int = 0
    }
class AdaptadorcustomVI(var context: Context, 
items:ArrayList<EstructuraDeVigas>): BaseAdapter() {

    var items:ArrayList<EstructuraDeVigas>? = null
    init {
        this.items = items

    }
    override fun getCount(): Int {
        return this.items?.count()!!   
    }

    override fun getItemId(position: Int): Long {

        return position.toLong()  
    }

    override fun getItem(position: Int): Any {

        return this.items?.get(position)!!   
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {

        var ViewHolderVIGA:ViewHolderVIGA? = null

        var vista: View? = convertView

        if (vista == null) {
            vista = LayoutInflater.from(context).inflate(R.layout.templateldv, null)
            ViewHolderVIGA = ViewHolderVIGA(vista)
            vista.tag = ViewHolderVIGA
        } else {
            ViewHolderVIGA = vista.tag as? ViewHolderVIGA    
        }

        val item = getItem(position) as EstructuraDeVigas
        ViewHolderVIGA?.Obra?.text = item.Obra
        ViewHolderVIGA?.Detalle?.text = item.Detalle
        ViewHolderVIGA?.Codigo?.text = item.Codigo
        ViewHolderVIGA?.VIGAS?.text = item.VIGAS
        ViewHolderVIGA?.Cantidad?.text = item.Cantidad.toString()
        ViewHolderVIGA?.Peso?.text = item.Peso.toString()

        return vista!!
    }
}



private class ViewHolderVIGA (vista: View) {
    var Obra: TextView? = null
    var Detalle: TextView? = null
    var Codigo: TextView? = null
    var VIGAS: TextView? = null
    var Cantidad: TextView? = null
    var Peso: TextView? = null

    init {

        Obra= vista.findViewById(R.id.ListaOBRA)
        Detalle = vista.findViewById(R.id.ListaDETALLE)
        Codigo = vista.findViewById(R.id.ListaCODIGO)
        VIGAS = vista.findViewById(R.id.ListaPLANOID)
        Cantidad = vista.findViewById(R.id.ListaCANTIDAD)
        Peso = vista.findViewById(R.id.ListaPESO)
    }
}
class EstructuraDeVigas(Obra:String, Detalle:String, Codigo:String, VIGAS:String, Cantidad:Int, Peso:Int) {

var Obra        : String = ""
var Detalle     : String = ""
var Codigo      : String = ""
var VIGAS       : String = ""
var Cantidad    : Int = 0
var Peso        : Int = 0

init {
    this.Obra = Obra
    this.Detalle = Detalle
    this.Codigo = Codigo
    this.VIGAS = VIGAS
    this.Cantidad = Cantidad
    this.Peso = Peso
  }
}
    
asked by Martin Fernandez 12.06.2018 в 13:23
source

0 answers