進捗率を計算する方法が思いつきませんでした。JSON を使用してデータを取得すると、すべてのデータが sqlite に挿入されます。このすべてのプロセスを計算し、asynctask の実行中にパーセンテージを表示したかったのです。
@Override
protected Void doInBackground(Void... params) {
//int progress = 0; //progress testing
//while(progress < 100) {
//progress += 10;
//SystemClock.sleep(1000);
//publishProgress(progress);
//}
getAllChannels(); //function get json data and insert db.
return null;
}
...
public void getAllChannels(){
try {
headline = jsheadline.getJSONArray(TAG_NEWLIST);
headline2 = jsheadline2.getJSONArray(TAG_NEWLIST2);
headline3 = jsheadline3.getJSONArray(TAG_NEWLIST3);
insertDatabase(headline,TABLE_HEADLINE);
insertDatabase(headline2,TABLE_HEADLINE2);
insertDatabase(headline3,TABLE_HEADLINE3);
}catch (Exception e) {
}
}
public void insertDatabase(JSONArray total, String tablename) throws JSONException{
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
for(int i = 0; i < total.length(); i++){
JSONObject c = total.getJSONObject(i);
// Storing each json item in tablecolumn
String subject = c.getString(KEY_NEWS_SUBJECT);
db.addNews(tablename, subject);
}
これは、データをsqliteに保存する方法の例です。私を導き出してください。編集:複数の挿入に関与する場合は?ありがとう