0

私は、総給与と、食料品、電気代、輸送、イ​​ンターネットなどの対応するものに費やす金額を取る必要がある金融アプリを開発しています.私は値を取得し、パーセンテージを計算しましたdouble。しかし、以下のステートメントはint値のみを取りますが、 in ではprogress barなく in に表示したいのですprogress dialog

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

4

1 に答える 1

1

私はあなたの質問を完全に理解していないか、次のように簡単です:

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

于 2013-01-03T08:59:41.903 に答える