0
在我的一個活動中,有一些計算和總價格將被計算。按下提交按鈕後,它應該顯示一個警告對話框你確定要支付盧比:XXX ... ?這裏XXX應該是我存儲在變量中的最終價格。在Android中的AlertDialog中訪問變量
in alertdialog.setTitle()我應該能夠訪問變量。
請幫我解決這個問題。
public void onPay()
{
getItems();
int rate = 0;
if(spare1_item.equals("Tyres") || qty_1.equals("Quantity"))
{
}
else
{
//Toast.makeText(getApplicationContext(), "Now you can pay", 5000).show();
db = this.openOrCreateDatabase("mobile_cycle_clinic", MODE_PRIVATE, null);
c = db.rawQuery("select price from sparelist where name = '"+spare1_item+"'", null);
if(c.moveToNext())
{
do{
price = c.getInt(c.getColumnIndex("price"));
}
while(c.moveToNext());
}
fianl1_qty = Integer.parseInt(qty_1);
rate = rate + price * fianl1_qty;
db.execSQL("insert into spares_items(cycle_id,item_name,quantity,total_price)values('"+cycle_id+"','"+spare1_item+"',"+fianl1_qty+","+rate+")");
//Toast.makeText(getApplicationContext(), ""+rate, 5000).show();
}
這裏率是一個靜態變量,而在另一個方法我應該使用該變量在alertDialog.setMeaasge()。
public void storeData(View v)
{
cycle_id = id.getText().toString();
if(cycle_id.equals("") || cycle_id.equals("null"))
{
Toast.makeText(getApplicationContext(), "Please Scan Cycle",5000).show();
}
else
{
AlertDialog.Builder pauseBuild = new AlertDialog.Builder(this);
pauseBuild.setTitle("Pay Alert");
pauseBuild.setMessage("Do you really want to Pay..?"+rate);
pauseBuild.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
//time = sdf.format(new Date());
onPay();
finish();
return;
} });
pauseBuild.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// show it
pauseBuild.show();
}
http://www.mkyong.com/android/android-custom-dialog-example/ – 2014-11-21 11:59:57
並有你的郵政編碼 – 2014-11-21 12:00:23
我不明白最新的問題。該var是否與顯示alertdialog的環境相同。如果是,那麼直接訪問它,如果沒有,然後使靜態和訪問它像「Activity.Var」 – therealprashant 2014-11-21 12:03:51