我有一个进度对话框,显示使用字节作为进度单位下载我的文件我想将进度单位转换为兆字节
public void initializeDialog()
{
this.pDialog = new ProgressDialog(act);
this.pDialog.setMessage("Download");
this.pDialog.setIndeterminate(false);
this.pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
this.pDialog.setCancelable(true);
}
public AsynchTest() {
initializeDialog();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog.setProgressNumberFormat("%1d MB / %2d MB");
pDialog.show();
pDialog.setProgress(0);
}
@Override
protected Void doInBackground(Void... params) {
downloadContent();
return null;
}
@Override
protected void onProgressUpdate(Integer... progress) {
pDialog.incrementProgressBy((int) byteToMB(progress[0]));
}
@Override
protected void onPostExecute(Void result) {
pDialog.dismiss();
}
我使用此函数将字节转换为 mb
public long byteToMB(long byteTransform)
{
long mb=1024L*1024L;
return byteTransform/mb;
}
我用来更新进度对话框的代码片段
byte data[] = new byte[1024];
while ((count = input.read(data)) != -1) {
asynch.publishProgress(count);
output.write(data, 0, count);
}
我像这样设置我的进度对话框的最大值
sizePDialog+=ConnectionManager.getLength(url);
pDialog.setMax((int) byteToMB(sizePDialog));
但是当我这样做时我会出现这个错误
04-07 20:09:55.119: E/AndroidRuntime(20166): java.lang.NumberFormatException: Invalid long: "%1d"
非常感谢你