私のスプラッシュ画面では、リモートサーバーからデータをダウンロード中に進行状況バーが表示されます。 リモートデータベースから3つのデータテーブルをダウンロードしています。 各テーブルは異なるサイズにすることができます。 各テーブルのダウンロードプロセスは、異なる機能によって呼び出されます。 データのダウンロード中に進捗バーを計算して更新したい。例えばデータベースのサイズに応じてProgressBarのサイズを計算する
: 表1 - 100行 表230の行 表3 - 方法doInBckgroundから呼び出されたデータのダウンロード230行を
:
@Override
protected void doInBackground(String... params) {
downloadTable1();
downloadTable2();
downloadTable3();
}
私は達成するための2つのオプションの考えこれは: 1) 3つのテーブルすべてからデータを取得してから、ダウンロードを開始する前に、ダウンロードしたデータの各行の割合をプログレスバーに表示します。 上記の例では、100 + 30 + 230 = 360行がダウンロードされます。 ダウンロードする各行は、0.27%進捗バーを進めます。
2) または、各テーブルのアドバンストから比例に設定し、それに応じて進捗量を設定します。たとえば、テーブル3が常に最大であると仮定すると、テーブル2は最小でテーブル1は真ん中にあります。 私はプログレスバーへの影響を修正することができます: 表1 30% 表2 20% 表3 50% 表3ダウンロードした各方法では、その量だけ進行を進めます。
私の質問は、サイズが異なる3つの異なるデータベーステーブルからデータをダウンロードしながら正確に進行する正確な進行状況バーを作成するというこの目標を達成するための一般的な方法です。データをダウンロードする方法の一つのための
例:
//Download Table1 data and save it in SQLite MAINCAT Table
private void downloadTable1() {
//-1 Code in PHP file to get Table1
String respond = getHttpRespond(-1); //The String respond got from HTTP request
DB_SQLiteManager db = new DB_SQLiteManager(context); //Prepare SQLite database object for future downloaded data
try {
JSONObject jsonObject = new JSONObject(respond); //the result in JSON
JSONArray jsonArray = jsonObject.getJSONArray("posts"); //result in Array of JSON
for (int i = 0; i < jsonArray.length(); i++) {
//Update progressbar value
totalProgressBarValue = totalProgressBarValue+i;
publishProgress(totalProgressBarValue);
JSONObject curr = jsonArray.getJSONObject(i); //Get current line
String strID = curr.optJSONObject("post").optString("id"); //Get current string ID
String strName = curr.optJSONObject("post").optString("name"); //Get current string et_Name
String imageLink = curr.optJSONObject("post").optString("imagelink");
String strPosition = curr.optJSONObject("post").optString("position");
//Insert row of data to SQLite MAINCAT table
db.addDataLineToTableMAINCAT(Integer.parseInt(strID), strName, imageLink, Integer.parseInt(strPosition));
System.out.println("ADDEDD: " + strID + strName + imageLink + strPosition);
}
} catch (Exception e) {
e.printStackTrace();
}
}
はありがとうは
downloadTableメソッドを表示してください – Zoe