Mysql
 SQL >> Datenbank >  >> RDS >> Mysql

Android: Text nach JSON-Request auf den UI-Thread bringen

Daten kommen im Hintergrund an, UI-Updates sind aber nur im Hauptthread erlaubt. Poste die Arbeit dorthin:

runOnUiThread(new Runnable() { @Override public void run() { try { txt3.setText(product.getString(TAG_DESCRIPTION)); } catch (JSONException e) { e.printStackTrace(); } } });

Vorher Objekt aus dem Array holen und View auflösen:

JSONObject product = productObj.getJSONObject(0); TextView txtName = findViewById(R.id.textView3);

Für neue Projekte sind ViewModel, LiveData oder Coroutines robuster als rohe Callbacks.