Je souhaite implémenter une vue de progression personnalisée sur l'adaptateur de base pour afficher la progression du téléchargement en arrière-plan, chaque seconde je vérifie la progression du téléchargement et met à jour mon modèle le progrès à l'interface utilisateur. Comme il est possible que l'UI rafraîchisse les opérations, je ne peux pas obtenir les événements de clic correctement. Que dois-je faire pour surmonter cela?Lorsque je notifait désactiver mon adaptateur chaque seconde, les événements de clic ne fonctionnent pas correctement
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
startJob();
}
}
});
t.start();
return START_STICKY;
}
début méthode de travail
public void startJob() {
BusStation.getMainThreadBus().post("deneme");
DownloadManager mDownloadManager = new DownloadManager(getContentResolver(),
getPackageName());
mDownloadManager.setAccessAllDownloads(true);
DownloadManager.Query myDownloadQuery = new DownloadManager.Query();
Cursor cursor = mDownloadManager.query(myDownloadQuery);
ArrayList<Integer> statuses = new ArrayList<>();
try {
DergilikApplication application = (DergilikApplication) getApplicationContext();
HashMap<String, DownloadInfo> downlodInfoHashMap = application.getDownlodInfoHashMap();
while (cursor.moveToNext()) {
int mIdColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
int mIdStatus = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS);
int mTotalBytesColumnId = cursor
.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
int mCurrentBytesColumnId = cursor
.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
int mDescrColumnId = cursor
.getColumnIndexOrThrow(DownloadManager.COLUMN_DESCRIPTION);
int uriId = cursor
.getColumnIndexOrThrow(DownloadManager.COLUMN_URI);
int localUriId = cursor
.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);
long totalBytes = cursor.getLong(mTotalBytesColumnId);
String desc = cursor.getString(mDescrColumnId);
long currentBytes = cursor.getLong(mCurrentBytesColumnId);
long downloadId = cursor.getLong(mIdColumnId);
int status = cursor.getInt(mIdStatus);
String localUri = cursor.getString(localUriId);
String uri = cursor.getString(uriId);
if (application.getProfile() != null && desc.contains(application.getProfile().getLoginNumber())) {
statuses.add(status);
DownloadInfo downlodInfo = new DownloadInfo();
downlodInfo.setCurrentProgress(currentBytes);
downlodInfo.setTotalProgress(totalBytes);
downlodInfo.setDescription(desc);
downlodInfo.setStatus(status);
downlodInfo.setDownloadId(downloadId);
downlodInfo.setUri(uri);
downlodInfo.setLocalUri(localUri);
downlodInfoHashMap.put(desc, downlodInfo);
}
}
application.setDownlodInfoHashMap(downlodInfoHashMap);
} finally {
cursor.close();
}
int counter = 0;
for (Integer status : statuses) {
if (!(status == DownloadManager.STATUS_FAILED || status == DownloadManager.STATUS_SUCCESSFUL)) {
counter++;
}
}
if (counter == statuses.size()) {
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
je pousse événement avec bibliothèque otto et ensemble de données notfy changé
@Subscribe
public void getMessage(String s) {
try {
dergilerAdapter.notifyDataSetChanged();
} catch (Exception e) {
e.printStackTrace();
}
//tvDownloaded.setText("% " + (int) (percentage * 100));
}
Avez-vous implémenté du code pour cela? Ou veut savoir comment pouvez-vous obtenir cela? – Piyush
notifydataset concerne les éléments de l'adaptateur .. ne devriez-vous pas essayer seulement de mettre à jour la barre de progression? –
@Tony mais mon progresbarr insite articles de l'adaptateur – hugerde