我的androidstudio应用程序未在列表视图中显示适配器

我的androidstudio应用程序未在列表视图中显示适配器,android,listview,android-fragments,Android,Listview,Android Fragments,我从我的网站解析一个JSON字符串并将其保存到Arraylist中,但是当我运行应用程序时,这些元素不会显示在片段中,我已经调试了,并且信息确实保存在Arraylist中,但它不会显示。我已经检查了类似的主题,但没有人解决我的问题。这是我的密码: 适配器: package com.example.luiggi.myapplication; import android.app.Activity; import android.content.Context; import android.vi

我从我的网站解析一个JSON字符串并将其保存到Arraylist中,但是当我运行应用程序时,这些元素不会显示在片段中,我已经调试了,并且信息确实保存在Arraylist中,但它不会显示。我已经检查了类似的主题,但没有人解决我的问题。这是我的密码:

适配器:

package com.example.luiggi.myapplication;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by andre_000 on 6/28/2015.
 */
public class FacturasAdapter extends ArrayAdapter<Invoices> {
    Context context;
    int layoutResourceId;
    ArrayList<Invoices> data;

    public FacturasAdapter(Context context, int layoutResourceId, ArrayList<Invoices> data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        FacturasHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new FacturasHolder();

            holder.shipping_id = (TextView) row.findViewById(R.id.shipping_id);
            holder.company_id = (TextView) row.findViewById(R.id.company_id);
            holder.user_id = (TextView) row.findViewById(R.id.user_id);
            holder.driver_id = (TextView) row.findViewById(R.id.driver_id);
            holder.id = (TextView) row.findViewById(R.id.id);
            holder.fecha_factura = (TextView) row.findViewById(R.id.fecha_factura);
            holder.monto = (TextView) row.findViewById(R.id.monto);
            holder.precio_km = (TextView) row.findViewById(R.id.precio_km);
            holder.nombre = (TextView) row.findViewById(R.id.nombre);
            holder.direccion = (TextView) row.findViewById(R.id.direccion);
            holder.telefono = (TextView) row.findViewById(R.id.telefono);
            holder.estado = (TextView) row.findViewById(R.id.estado);

            row.setTag(holder);
        } else {
            holder = (FacturasHolder) row.getTag();
        }

        Invoices pedido = data.get(position);

        holder.shipping_id.setText(pedido.shipping_id);
        holder.company_id.setText(pedido.company_id);
        holder.user_id.setText(pedido.user_id);
        holder.driver_id.setText(pedido.driver_id);
        holder.id.setText(pedido.id);
        holder.fecha_factura.setText(pedido.fecha_factura);
        holder.monto.setText(pedido.monto);
        holder.precio_km.setText(pedido.precio_km);
        holder.nombre.setText(pedido.nombre);
        holder.direccion.setText(pedido.direccion);
        holder.telefono.setText(pedido.telefono);
        holder.estado.setText(pedido.estado);

        //final int pos = position;

        /*row.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PresupuestosFragment.presupuestoSeleccionado = PresupuestosFragment.listPresupuestos.get(pos);

                new PresupuestoRepuestoTask().execute();
            }
        });
*/
        return row;
    }



    static class FacturasHolder {
        public TextView shipping_id;
        public TextView company_id;
        public TextView user_id;
        public TextView driver_id;
        public TextView id;
        public TextView fecha_factura;
        public TextView monto;
        public TextView precio_km;
        public TextView nombre;
        public TextView direccion;
        public TextView telefono;
        public TextView estado;

    }
}
片段:

package com.example.luiggi.myapplication;

import android.app.Activity;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

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

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;


public class FacturasFragments extends Fragment {

    View rootView;
    private ListView ListFacturas;


    //public static Presupuestos presupuestoSeleccionado;
    //public static ArrayList<PresupuestoRepuesto> presupuestoRepuesto;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        rootView=inflater.inflate(R.layout.facturas_fragments, container, false);

        ListFacturas = (ListView)rootView.findViewById(R.id.ListFacturas);

        Jsonclass conexion = new Jsonclass();
        conexion.execute();



        return rootView;
    }

    public class Jsonclass extends AsyncTask<Void, Void, String> {
        public ArrayList<Invoices> listfacturas;

        @Override
        protected String doInBackground(Void... params) {
            WebRequest facturas = null;

            try {
                facturas = new WebRequest(
                        "http://gruasochoa.herokuapp.com/invoiceapi/index.json"
                );
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            } catch (URISyntaxException e) {
                e.printStackTrace();
                return null;
            }

            return facturas.getResponse();
        }

        @Override
        protected void onPostExecute(final String result) {
            //if (result != null) {
            //Log.v("Prueba",result);
            listfacturas = StringToFacturas(result);
            ListFacturas.setAdapter(new FacturasAdapter(getActivity(),R.layout.facturasadapterview, listfacturas));

            //} else {

            //}
        }

        // TODO: Convertir string a JSON y luego a ArrayList<presupuestos>
        private ArrayList<Invoices> StringToFacturas(String result) {
            ArrayList<Invoices> listfacturas = new ArrayList<Invoices>();

            try {
                JSONArray presupuestos = new JSONArray(result);

                for (int i = 0; i < presupuestos.length(); i++) {
                    //JSONArray p = presupuestos.getJSONObject(i).getJSONArray("presupuestos");

                    //for (int j = 0; j < p.length(); j++) {


                    Invoices invoice = new Invoices(
                            presupuestos.getJSONObject(i).getString("id"),
                            presupuestos.getJSONObject(i).getString("shipping_id"),
                            presupuestos.getJSONObject(i).getString("company_id"),
                            presupuestos.getJSONObject(i).getString("user_id"),
                            presupuestos.getJSONObject(i).getString("driver_id"),
                            presupuestos.getJSONObject(i).getString("fecha_factura"),
                            presupuestos.getJSONObject(i).getString("monto"),
                            presupuestos.getJSONObject(i).getString("precio_km"),
                            presupuestos.getJSONObject(i).getString("nombre"),
                            presupuestos.getJSONObject(i).getString("direccion"),
                            presupuestos.getJSONObject(i).getString("telefono"),
                            presupuestos.getJSONObject(i).getString("estado")
                            //p.getJSONObject(j).getJSONObject("usuario").getString("correo") + " (" + p.getJSONObject(j).getJSONObject("usuario").getString("nombre") + " " + p.getJSONObject(j).getJSONObject("usuario").getString("apellido") + ")"
                    );

                    listfacturas.add(invoice);
                    //}
                }




                //JSONObject jsonResponse = new JSONObject(result);
                //Log.v("FINAPARTY", result);


                //Log.v("FINAPARTY", presupuestos.getJSONObject(0).getString("fecha_registro"));

                //Log.v("FINAPARTY", presupuestos.getJSONObject(0).getJSONArray("presupuestos").getJSONObject(0).getString("id_usuario"));

            } catch (JSONException e) {
                e.printStackTrace();
            }



            return listfacturas;
        }
    }


}
片段XML:

<!-- TODO: Update blank fragment layout -->

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ListFacturas"
    android:layout_gravity="center_horizontal|top"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="0dp"
    android:layout_alignParentTop="true"
    android:layout_marginTop="0dp" />
适配器XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/shipping_id"
        android:layout_gravity="bottom"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="0dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/company_id"
        android:layout_gravity="center_vertical"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="52dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/user_id"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="104dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/driver_id"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="156dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/id"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="208dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/fecha_factura"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="260dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/monto"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="312dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/precio_km"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="364dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/nombre"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="416dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/direccion"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="468dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/telefono"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="520dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/estado"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="0dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="572dp" />

</RelativeLayout>

看起来不错。试着记录你拥有的列表的大小。listfacturas的大小像listfacturas.sizeoh好的,但是我应该把它放在哪里?在适配器中?我已经尝试在返回data.size的适配器中使用GetCount方法;在onCreateView期间,您是否尝试使用空数据集将适配器传递到列表视图,然后在onPostExecute中简单地更新数据集?你的问题可能在那里,但我不确定我更像一个回收者=