我正在使用android 2.3.3的進度對話框。進度對話框的狀態顯示格式爲「60%60/100」,但我只想顯示不是「60/100」的百分比。我該怎麼做?請幫忙。如何按百分比顯示進度條狀態
11
A
回答
1
請訪問this鏈接。
另外它在SDK中的ApiDemos中完整解釋。您想要的示例名爲:ProgressBar3.java並且可以在\ ApiDemos \ src \ com \ example \ android \ apis \ view \
中找到另外,如果要刪除對話框的邊框,出現進度條時,您可以將對話框本身定義爲透明視圖/覆蓋圖(這也在示例中進行了說明)。
17
據documentation,你應該叫setProgressNumberFormat (null)
您ProgressDialog
實例來獲得這種行爲
11
嘿這裏從服務器下載文件,保存文件到SD卡,並顯示一個進度條。
public class XYZ extends Activity {
public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
private Button startBtn;
private ProgressDialog mProgressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startBtn = (Button)findViewById(R.id.startBtn);
startBtn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
startDownload();
}
});
}
private void startDownload() {
String url = "http://.jpg";
new DownloadFileAsync().execute(url);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_DOWNLOAD_PROGRESS:
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Downloading file..");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
return mProgressDialog;
default:
return null;
}
}
class DownloadFileAsync extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(DIALOG_DOWNLOAD_PROGRESS);
}
@Override
protected String doInBackground(String... aurl) {
int count;
try {
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/some_photo_from_gdansk_poland.jpg");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+(int)((total*100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {}
return null;
}
protected void onProgressUpdate(String... progress) {
Log.d("ANDRO_ASYNC",progress[0]);
mProgressDialog.setProgress(Integer.parseInt(progress[0]));
}
@Override
protected void onPostExecute(String unused) {
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}
}
}
這樣你..
這個例子形象我淨找到。
,這是我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:text="Start long running task.."
android:id="@+id/startBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
+5
這不是問題的答案 – SoroushA 2016-03-23 19:31:40
相關問題
- 1. 顯示進度條上的進度百分比
- 2. AJAX進度條顯示頁面加載的進度百分比
- 3. 如何在AngularJS中顯示百分比文字進度條?
- 4. 如何顯示上傳進度條的百分比?
- 5. 如何以百分比顯示進度條?
- 6. Twitter的引導:用百分比顯示進度條中心
- 7. 在ajax中顯示加載百分比的進度條,php
- 8. 顯示進度條完成百分比C#項目
- 9. 進度條百分比與條動態一起移動嗎?
- 10. 如何顯示計時器的進度百分比
- 11. 如何使用進度欄顯示下載的百分比?
- 12. 如何顯示progressBar中的綠色進度和百分比?
- 13. 如何在dropzone.js中顯示上傳進度百分比
- 14. Qt進度條百分比問題
- 15. Ajax加載進度條百分比
- 16. 計算進度條百分比
- 17. 計算進度百分比
- 18. 計算進度百分比
- 19. AQuery在進度條上以進度百分比加載圖像
- 20. 如何在JavaScript中爲我的進度條設置百分比?
- 21. 如何顯示百分比在python
- 22. 顯示進度百分比複製文件
- 23. 用JProgressBar以百分比數顯示線程進度
- 24. 刪除顯示在進度對話框下方的百分比
- 25. jquery循環進度顯示不正確的百分比
- 26. 如何按百分比
- 27. 如何使用百分比高度顯示錶格中的div的滾動條
- 28. 百分比顯示問題
- 29. 顯示和百分比
- 30. 擅長進度百分比進行
,你所提到的方法適用於API級別11.我的是10 – Dhanesh 2012-01-28 07:38:18
我的壞:(我已經挖成的源代碼,並找出在api 10中沒有「正常」的方法。我可以提出一種解決方法,從Android 4.0.1獲取完整的ProgessDialog代碼,並使用它代替內置版本。也許,它會有些混亂android「內部」資源,但它也可作爲重用源。 – OleGG 2012-01-28 08:13:02