I am successfully calling for and receiving json data... I am not getting any errors... Logcat is displaying the proper information... I can hard code setTextViewsText outside of the request... But, my city TextView is not changing in this block of code!
I've been struggling with this for two days and I've tried everything I can think of and everyting I could find on stackoverflow. I am relatively new to Kotlin and Android, so please be gentle. ;)
val queue = Volley.newRequestQueue(context)
views.setTextViewText(R.id.city, "Some City") // this works
val jsonObjectRequest =
JsonObjectRequest(Request.Method.GET, url, null,
{ response ->
try {
val yourCity = response.getString("name")
views.setTextViewText(R.id.city, yourCity) // this doesn't work
Log.i("city", "Your City: $yourCity ")
} catch (e: JSONException) {
e.printStackTrace()
}
}
) { }
queue.add(jsonObjectRequest)
appWidgetManager.updateAppWidget(appWidgetId, views)
Logcat displays:
I/city: Your City: Mountain View
Manifest includes:
<uses-permission android:name="android.permission.INTERNET" />
build.gradle:
dependencies {
...
implementation 'com.android.volley:volley:1.1.1'
...
}
You're doing good, but you have to call updateAppWidget()
after views.setTextViewText(R.id.city, yourCity)
, to update the view on user's screen.