我正在尝试将MySQL lite数据库中的列表填充到列表视图中。我找到了一些CursorAdaptor很好的教程,以便我可以根据id更新列表。
但我尝试了这些教程,而listview中没有列出任何数据。
我将内容添加到数据库并将其更新为:
{
if(count > 0){
String earlierQty = mydb.getDataFromList("qty",item.getId(),tabid);
BigDecimal updatedQty = new BigDecimal(earlierQty).setScale(2).add(new BigDecimal(item.getQty()).setScale(2));
BigDecimal updatedAmount = setCurrentAmount(item.getId(),updatedQty,tabid);
total = setTotalAmount(updatedAmount,new BigDecimal(item.getTax()).setScale(2));
taxamount = setTaxAmount(updatedAmount,new BigDecimal(item.getTax()).setScale(2));
mydb.updateARowByProductId(item.getTitle(), "pos", String.valueOf(updatedAmount),String.valueOf(updatedQty),new BigDecimal(item.getUnitPrice()).setScale(2).toString(),item.getDiscount(),String.valueOf(taxamount),item.getQuantityin(),String.valueOf(total),tabid,item.getId());
}
else{
Log.e("PRICE ",item.getUnitPrice());
total = new BigDecimal(item.getUnitPrice()).setScale(2).multiply(new BigDecimal(item.getTax()).setScale(2).divide(new BigDecimal(100)));
total = total.add(new BigDecimal(item.getUnitPrice()).setScale(2)).setScale(2);
taxamount = setTaxAmount(new BigDecimal(item.getUnitPrice()),new BigDecimal(item.getTax()).setScale(2));
Log.e("taxamount",taxamount.toString());
mydb.addContact(new ListItem(item.getTitle(), "pos", new BigDecimal(item.getUnitPrice()).setScale(2).toString(),new BigDecimal(item.getQty()).setScale(2).toString(),new BigDecimal(item.getUnitPrice()).setScale(2).toString(),item.getDiscount(),tabid,item.getId(),String.valueOf(taxamount),item.getQuantityin(),total.toString()));
}
showList(tabid);
}
我的ShowList函数正在尝试将值填充到列表中:
public void showList(String tab_id){
Cursor listdata = mydb.getAllCursorTabItems(tab_id);
try {
mListAdapter = new ListviewCursorAdapter(getActivity(), listdata);
mListview.setAdapter(mListAdapter);
} catch (Exception e) {
} finally {
//mListAdapter.changeCursor(listdata);
//scrollMyListViewToBottom();
BigDecimal subtotalValue = new BigDecimal(mydb.getProductListAmountSUM(tab_id)).setScale(2);
BigDecimal discountvalue = new BigDecimal(mydb.getProductListDiscountSUM(tab_id)).setScale(2);
BigDecimal taxvalue = new BigDecimal(mydb.getProductListAmountTAX(tab_id)).setScale(2);
BigDecimal totalvalue = new BigDecimal(mydb.getProductListTotalSUM(tab_id)).setScale(2);
totalvalue = totalvalue.subtract(discountvalue).setScale(2);
subtotal.setText(subtotalValue+" "+getString(R.string.rs));
discount.setText(discountvalue+" "+getString(R.string.rs));
tax.setText(taxvalue.toString()+" "+getString(R.string.rs));
total.setText(totalvalue.toString()+" "+getString(R.string.rs));
}
}
我的适配器类是:
public class ListviewCursorAdapter extends CursorAdapter {
public ListviewCursorAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
}
// The newView method is used to inflate a new view and return it,
// you don't bind any data to the view at this point.
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.list_row, parent, false);
}
// The bindView method is used to bind all data to a given view
// such as setting the text on a TextView.
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Find fields to populate in inflated template
TextView name = (TextView) view.findViewById(R.id.name);
TextView type = (TextView) view.findViewById(R.id.type);
TextView amount = (TextView) view.findViewById(R.id.amount);
// Extract properties from cursor
String text_name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
String text_type = cursor.getString(cursor.getColumnIndexOrThrow("type"));
String text_amount = cursor.getString(cursor.getColumnIndexOrThrow("amount"));
String text_qty = cursor.getString(cursor.getColumnIndexOrThrow("quantity"));
String text_unit = cursor.getString(cursor.getColumnIndexOrThrow("unit"));
String text_price = cursor.getString(cursor.getColumnIndexOrThrow("price"));
String text_discount = cursor.getString(cursor.getColumnIndexOrThrow("discount"));
String discription = text_qty + " "+text_unit+ " at " +text_price +"/"+text_unit+" with discount "+text_discount;
name.setText(text_name);
type.setText(discription);
amount.setText(text_amount);
}
}
更新
我抓住了名单:
出现错误:
E / ERROR:java.lang.IllegalArgumentException:column' _id'才不是 存在