2013-01-03 26 views
0

我發展金融應用應採取工資總額和金額顯示的百分比花費相應的東西說雜貨,電費,運輸,internet.I所採取的值並計算出現在的百分比,因爲計算的結果是double。但是,下面的語句只取int價值,但我想在progress dialogprogress bar不顯示。添加整數和計算比例,並用進度條

progressDialog.incrementProgressBy(x); 
int amount2 = b.getInt("restaurant",2); 
double res = ((double)amount2/amount) * 100; 
TextView txt2 = (TextView) findViewById(R.id.tv2); 
txt2.setText("percentage2\t" + res); 

的量爲總的工資和amount2是餐館賬單。所以,現在的百分比值 是double,現在有progress bar顯示。

+0

progressDialog.show(); –

+1

你應該嘗試使用名稱其指示有關上下文。 – stealthjong

+0

什麼聲明需要和int,在這裏?我看不出問題會在哪裏。 – njzk2

回答

0

要麼我不完全明白你的問題,或者它是如此簡單:

int totalIncome = getTotalIncome(); //or however you retrieve the totalIncome 
int restaurantExpense = bundle.getInt("restaurant", 2); 
double percentage = ((double)restaurantExpense/totalIncome) * 100; 
((ProgressBar)findViewById(R.id.myprogressbar)).setProgress((int)percentage); 

但我仍然不知道爲什麼你使用ProgressDialog,然後說你不想使用它。

編輯:您還可以使用totalIncome爲最大:

myProgressbar.setMax(totalIncome); 
myProgressbar.setProgress(restaurantExpense); 

現在,您可以省略計算,你沒有投什麼int