-1
마지막 요소를 보여 유일한 드 목록보기의 마지막 요소를 보여customadapter 만 내 어댑터에 문제가
전화 어댑터 :
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;
}
}
어댑터 :
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;
}
}
예를 들어 데이터베이스에 3 개의 항목이 있습니다 : shosho, bosho, gosho 결과적으로 목록보기에는 gosho 만 있습니다. 어떤 생각을 어떻게 고쳐야합니까?
미리 감사드립니다. 모든 도움을 감사