0
Hier ist mein Code:Retrofit asynchrones Tash
private void InitialContact(final Context context)
{
final ContactDatabase db = new ContactDatabase(context);
context.openOrCreateDatabase("****", MODE_PRIVATE, null);
if(refrech){
refrech(db, context);
}
getcontact(db, context);
db.close();
}
A getContact fonction (In Hauptthread)
private void getcontact(final ContactDatabase db, final Context context){
SQLiteDatabase dbread = db.getReadableDatabase();
String[] retour = {
"pseudo",
"adresse",
"image", "ID"
};
Cursor cursor = dbread.query("Contact", retour, null, null, null, null, "pseudo");
while(cursor.moveToNext()) {
String pseudo = cursor.getString(cursor.getColumnIndexOrThrow("pseudo"));
Log.d("debug", "getcontact: "+pseudo);
listcontact.add(new Contact(pseudo));
}
cursor.close();
}
Und die Asynchrone Aufgabe aktualisieren
private void refrech(final ContactDatabase db, final Context context){
final SQLiteDatabase dbwrite = db.getWritableDatabase();
db.onRefresh(dbwrite);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
int ID = preferences.getInt("ID", 0);
if(ID != 0){
ApiInterface mApiService = this.getInterfaceService();
Call<ContactCall> mService = mApiService.getcontact(ID);
mService.enqueue(new Callback<ContactCall>() {
@Override
public void onResponse(Call<ContactCall> call, Response<ContactCall> response) {
ContactCall ContactCallobjet = response.body();
ArrayList pseudo = ContactCallobjet.isLogin;
for(int i = 0 ;pseudo.size() <= i; i++){
ContentValues values = new ContentValues();
String contact = (String) pseudo.get(i);
values.put("pseudo", contact);
values.put("adresse", "test");
values.put("image", "test");
values.put("ID", "5");
dbwrite.insert("Contact", null, values);
}
}
@Override
public void onFailure(Call<ContactCall> call, Throwable t) {
Log.d("DEBUG", "populateWithInitialContacts: "+t.getMessage());
}
});
} else {
Log.d("DEBUG", "populateWithInitialContacts: Error ID");
}
}
Meine Probleme ist ein getContact Funktion ist Aufruf vor einer asynchronen Funktion (Refrech) Ich habe einen CallBack Test, aber es tat es nicht arbeiten
, die sich wie eine andere Frage (auch die Fehlerprotokollierung Stacktrace und Informationen über den Kontakt Tablette enthalten) zu stellen scheint. Wenn Sie festgestellt haben, dass diese Antwort Ihre Frage gelöst hat, akzeptieren Sie sie als Antwort. – petey
Tatsächlich ist dies keine Antwort, die wegen der asynchronen Aufgabe funktioniert. Meine 'private Liste listcontact;' Ich fülle 'listcontact.add (neuer Kontakt (Pseudo)) aus;' Ist am Ende des Tash klar –
therapha361