0
내 액티비티에는 약간의 계산이 있고 총 가격이 계산됩니다. 제출 버튼을 누르면 다음과 같은 경고 대화 상자가 나타납니다 : 루피 : XXX ... ? 여기서 XXX는 내가 변수에 저장하고있는 최종 가격이어야합니다.안드로이드에서 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();
}
여기 레이트 정적 변수 및 다른 방법은 I 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/ –
및 코드가 –
인 게시물을 가지고 있습니다. 문제는 무엇인지 이해하지 못합니다. alertdialog를 표시하고있는 동일한 컨텍스트의 var입니까? 만약 그렇다면 직접 액세스하지 않는 다음 정적 var 및 "Activity.Var"처럼 액세스 할 수 – therealprashant