Хе, я делаю приложение для кассира. Может кто-нибудь сказать мне, как удерживать номер приращения для купленного списка? У кассира есть список товаров клиента, затем покупатель идет, берет какой-то товар и хочет его удержать. Сначала отсканируйте товар другого клиента. Например, я держу номер счета 1. Итак, следующий счет будет 2. Когда я заплатил за счет 2, значит, это будет счет 3, верно? Так что теперь я перезваниваю, чтобы оплатить счет 1. Когда я заплатил для первого счета счет стал отсчитываться до счета 2. Но счет 2 я уже оплатил. Как сохранить инкрементный номер счета?
это MainActivity.class
Hold.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String invoice = txt_referName.getText().toString() + txt_referNum.getText().toString();
insertHoldListMaster(invoice);
myDb.deleteAllItemPurchased();
displayItemPurchased(MainActivity.this);
}
});
AdapterHoldList.class
открытый класс AdapterHoldList расширяет RecyclerView.Adapter {
private Context ctx;
private LayoutInflater inflater;
private ArrayList<Product_Item> itemsList;
//SQLite
DatabaseHelper myDb;
DecimalFormat format = new DecimalFormat("0.00");
public AdapterHoldList(Context ctx, ArrayList<Product_Item> itemsList){
inflater = LayoutInflater.from(ctx);
this.ctx = ctx;
this.itemsList = itemsList;
}
public class HoldListViewHolder extends RecyclerView.ViewHolder{
public TextView invoice, timestamp, totalPrice;
public Button btnReadyPay, btnDel;
public HoldListViewHolder(@NonNull View itemView) {
super(itemView);
invoice = itemView.findViewById(R.id.txt_holdReferBill);
timestamp = itemView.findViewById(R.id.txtHold_DateTimeBill);
totalPrice = itemView.findViewById(R.id.txtHold_TotalPriceBill);
btnReadyPay = itemView.findViewById(R.id.btn_holdReadyPay);
btnDel = itemView.findViewById(R.id.btn_holdDel);
}
}
@NonNull
@Override
public HoldListViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = inflater.inflate(R.layout.recycler_view_hold_list, viewGroup, false);
myDb = new DatabaseHelper(ctx);
return new HoldListViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final HoldListViewHolder holder, final int position) {
DecimalFormat format = new DecimalFormat("0.00");
final Product_Item item = itemsList.get(position);
final Double itemAmt = item.getItemTotalPrice();
final String invoice = item.getInvoice();
String strItemPrice = format.format(itemAmt);
holder.invoice.setText(item.getInvoice());
holder.timestamp.setText(item.getTimestamp());
holder.totalPrice.setText(strItemPrice);
holder.btnReadyPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean success = AddToList(invoice);
if (success) {
MainActivity.displayItemPurchased(ctx);
((Activity)ctx).finish();
}
}
});
holder.btnDel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteHoldList(holder.getAdapterPosition(), invoice);
}
});
}
@Override
public int getItemCount() {
return itemsList.size();
}
private void deleteHoldList(int position, String invoice){
myDb.deleteHoldListDt(invoice);
myDb.deleteHoldList(invoice);
itemsList.remove(position);
notifyItemRemoved(position);
HoldListActivity.displayHoldList(ctx);
myDb.close();
}
private boolean AddToList(String invoice){
myDb.deleteAllItemPurchased();
Cursor cursorHold = myDb.getAllHoldListDtByInvoice(invoice);
while (cursorHold.moveToNext()) {
String itemId = cursorHold.getString(1);
String itemDescription = cursorHold.getString(2);
Double itemUnitPrice = cursorHold.getDouble(3);
int itemQty = cursorHold.getInt(4);
Double itemTotalPrice = cursorHold.getDouble(5);
myDb.insertItemPurchased(itemId,itemDescription,itemUnitPrice,itemQty,itemTotalPrice);
}
myDb.close();
return true;
}
}
Способ оплаты.класс
btn_paymentPayNow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (txtCard.getVisibility() == View.VISIBLE){
PaymentPayCredit();
}else{
PaymentPayCash();
}
}
});
public void PaymentPayCash(){
Double paid = Double.valueOf(txtPaid.getText().toString());
Double change = Double.valueOf(txtChange.getText().toString());
if (paid > 0 && change >= 0) {
AlertDialog.Builder alertDialog = (new AlertDialog.Builder(PaymentMethod.this));
alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Double totalPay = Double.valueOf(txt_AmtDue.getText().toString());
Double totalDisc = Double.valueOf(txtDetailDiscount.getText().toString());
Double UserPaid = Double.valueOf(txtPaid.getText().toString());
Double BalancePaid = Double.valueOf(txtChange.getText().toString());
myDb.insertSuccessPayMaster(prefix + suffix,"","","",totalPay,totalDisc, UserPaid, BalancePaid);
insertSuccessPayDt();
myDb.deleteAllItemPurchased();
MainActivity.displayItemPurchased(PaymentMethod.this);
//exit cash sales
progressDialog = new ProgressDialog(PaymentMethod.this);
progressDialog.setMessage("Processing...");
progressDialog.show();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
Toast.makeText(PaymentMethod.this,"Payment Succesfull",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(PaymentMethod.this,PrintSuccessPayCash.class);
intent.putExtra("InvoiceNo", prefix + suffix );
startActivity(intent);
suffix++;
myDb.insertPrefix(prefix, suffix,"invoice");
finish();
}
}
}, 2000);
}
});
alertDialog.setNegativeButton("No", null);
alertDialog.setMessage("Confirm to Pay & Print " + prefix + suffix + " ?");
alertDialog.setTitle("Confirmation");
alertDialog.show();
} else {
Toast.makeText(PaymentMethod.this,"Please pay enough amount",Toast.LENGTH_SHORT).show();
}
}
Кстати, я делаю приращение к суффиксу ++ .. Как это решить? Если вы можете помочь моему коду, хорошо, просто помогите мне с идеей удерживать функцию увеличения номера счета .. Заранее спасибо.




Вы можете использовать TextWatcher для запуска события, когда пользователь вводит данные в текстовое поле. После этого вы можете произвести расчеты.
https://developer.android.com/reference/android/text/TextWatcher
public class MyFragment extends Fragment implements TextWatcher {
//some other code...
@Override
public void afterTextChanged(Editable s) {
//TODO: Calculations...
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//Nothing to do here...
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//Nothing to do here...
}
}
Хорошо, это то, что мне нужно знать, спасибо.
никто не знает, какова ваша формула расчета. Что именно является проблемой для вас, чтобы делать то, что вы хотите?