Skip to content

Instantly share code, notes, and snippets.

@AkshatAgrawal05
Created August 25, 2017 10:03
Show Gist options
  • Save AkshatAgrawal05/8e531fca2be769f926bcafe6e93ae5e1 to your computer and use it in GitHub Desktop.
Save AkshatAgrawal05/8e531fca2be769f926bcafe6e93ae5e1 to your computer and use it in GitHub Desktop.
Async Task to read json file
private inner class JsonExecuter : AsyncTask<Void, Void, String>() {
override fun doInBackground(vararg p0: Void?): String {
return getJsonFromAssets()!!
}
override fun onPostExecute(result: String?) {
super.onPostExecute(result)
val moshi = Moshi.Builder().build()
val jsonAdapter = moshi.adapter(Reddit::class.java)
var red: Reddit? = jsonAdapter.fromJson(result)
mList = red?.data?.children!!
rvReddit?.adapter = RedditAdapter(mContext, mList)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment