Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android customadapter仅显示最后一个元素_Android_Arraylist_Adapter_Android Arrayadapter - Fatal编程技术网

Android customadapter仅显示最后一个元素

Android customadapter仅显示最后一个元素,android,arraylist,adapter,android-arrayadapter,Android,Arraylist,Adapter,Android Arrayadapter,我的适配器有问题,它只显示de listview上的最后一个元素 呼叫适配器: public class listrestadp extends BaseAdapter { // Declare Variables Context context; String[] prdesc; Integer[] cant; Integer[] comensal; Integer[] tiempo; Integer[] idpr; LayoutInflater inflater; ArrayList<

我的适配器有问题,它只显示de listview上的最后一个元素

呼叫适配器:

public class listrestadp extends BaseAdapter {
// Declare Variables
Context context;
String[] prdesc;
Integer[] cant;
Integer[] comensal;
Integer[] tiempo;
Integer[] idpr;

LayoutInflater inflater;
ArrayList<datoscomanda> lista;

public listrestadp(Context context, String[] prdesc, Integer[] cant, Integer[] comensal, Integer[] tiempo,Integer[] idpr) {
    this.context = context;
    this.prdesc = prdesc;
    this.cant = cant;
    this.comensal = comensal;
    this.tiempo = tiempo;
    this.idpr = idpr;
    lista = new ArrayList<>();
    for (int i = 0; i < prdesc.length; i++) {
        lista.add(new datoscomanda(prdesc[i],cant[i],comensal[i],tiempo[i],idpr[i]));
    }


}

@Override
public int getCount() {
    return lista.size();
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}

public View getView(final int position, View convertView, ViewGroup parent) {

    // Declare Variables
    TextView txtprd;
    TextView txtcnt;
    TextView txtcomensal;
    TextView txtiempo;
    Button btnxpr;


            //http://developer.android.com/intl/es/reference/android/view/LayoutInflater.html
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View itemView = inflater.inflate(R.layout.lay_popup, parent, false);

    // Locate the TextViews in listview_item.xml
    txtprd = (TextView) itemView.findViewById(R.id.txtprd);
    txtcnt = (TextView) itemView.findViewById(R.id.txtcnt);
    txtcomensal = (TextView) itemView.findViewById(R.id.txtcomensal);
    txtiempo = (TextView) itemView.findViewById(R.id.txtiempo);
    btnxpr = (Button) itemView.findViewById(R.id.btndelpr);

    // Capture position and set to the TextViews
    txtprd.setText(lista.get(position).prdesc);
    txtcnt.setText(Integer.toString(lista.get(position).cantidad));
    txtcomensal.setText(Integer.toString(lista.get(position).comensal));
    txtiempo.setText(Integer.toString(lista.get(position).tiempo));
    btnxpr.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DBhelper dbhelper = new DBhelper(context);
            SQLiteDatabase dbs = dbhelper.getWritableDatabase();
            lista.remove(position);
            dbs.delete(DBhelper.TABLE_COMANDA, DBhelper.KEY_ID+"="+lista.get(position).idpr, null);
            listrestadp.this.notifyDataSetChanged();
        }
    });

    return itemView;
}
公共类listrestadp扩展BaseAdapter{
//声明变量
语境;
字符串[]prdesc;
整数[]超高;
整数[]comensal;
整数[]tiempo;
整数[]idpr;
充气机;
ArrayList lista;
public listrestadp(上下文上下文,字符串[]prdesc,整数[]铁路超高,整数[]comensal,整数[]tiempo,整数[]idpr){
this.context=上下文;
this.prdesc=prdesc;
this.cant=铁路超高;
this.comensal=comensal;
this.tiempo=tiempo;
这是Idr=Idr;
lista=新的ArrayList();
对于(int i=0;i
}

适配器:

public class listrestadp extends BaseAdapter {
// Declare Variables
Context context;
String[] prdesc;
Integer[] cant;
Integer[] comensal;
Integer[] tiempo;
Integer[] idpr;

LayoutInflater inflater;
ArrayList<datoscomanda> lista;

public listrestadp(Context context, String[] prdesc, Integer[] cant, Integer[] comensal, Integer[] tiempo,Integer[] idpr) {
    this.context = context;
    this.prdesc = prdesc;
    this.cant = cant;
    this.comensal = comensal;
    this.tiempo = tiempo;
    this.idpr = idpr;
    lista = new ArrayList<>();
    for (int i = 0; i < prdesc.length; i++) {
        lista.add(new datoscomanda(prdesc[i],cant[i],comensal[i],tiempo[i],idpr[i]));
    }


}

@Override
public int getCount() {
    return lista.size();
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}

public View getView(final int position, View convertView, ViewGroup parent) {

    // Declare Variables
    TextView txtprd;
    TextView txtcnt;
    TextView txtcomensal;
    TextView txtiempo;
    Button btnxpr;


            //http://developer.android.com/intl/es/reference/android/view/LayoutInflater.html
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View itemView = inflater.inflate(R.layout.lay_popup, parent, false);

    // Locate the TextViews in listview_item.xml
    txtprd = (TextView) itemView.findViewById(R.id.txtprd);
    txtcnt = (TextView) itemView.findViewById(R.id.txtcnt);
    txtcomensal = (TextView) itemView.findViewById(R.id.txtcomensal);
    txtiempo = (TextView) itemView.findViewById(R.id.txtiempo);
    btnxpr = (Button) itemView.findViewById(R.id.btndelpr);

    // Capture position and set to the TextViews
    txtprd.setText(lista.get(position).prdesc);
    txtcnt.setText(Integer.toString(lista.get(position).cantidad));
    txtcomensal.setText(Integer.toString(lista.get(position).comensal));
    txtiempo.setText(Integer.toString(lista.get(position).tiempo));
    btnxpr.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DBhelper dbhelper = new DBhelper(context);
            SQLiteDatabase dbs = dbhelper.getWritableDatabase();
            lista.remove(position);
            dbs.delete(DBhelper.TABLE_COMANDA, DBhelper.KEY_ID+"="+lista.get(position).idpr, null);
            listrestadp.this.notifyDataSetChanged();
        }
    });

    return itemView;
}
公共类listrestadp扩展BaseAdapter{
//声明变量
语境;
字符串[]prdesc;
整数[]超高;
整数[]comensal;
整数[]tiempo;
整数[]idpr;
充气机;
ArrayList lista;
public listrestadp(上下文上下文,字符串[]prdesc,整数[]铁路超高,整数[]comensal,整数[]tiempo,整数[]idpr){
this.context=上下文;
this.prdesc=prdesc;
this.cant=铁路超高;
this.comensal=comensal;
this.tiempo=tiempo;
这是Idr=Idr;
lista=新的ArrayList();
对于(int i=0;i
}

例如,我的数据库中有3个条目:shosho、bosho、gosho,因此我的listview中只有gosho。知道怎么解决吗

提前谢谢!
感谢所有帮助

项目是:

@Override
public Object getItem(int position) {
    return lista.get(position);
}
尝试更改getItem,然后使用

txtprd.setText(getItem(position).prdesc);