小编Aro*_*mic的帖子

Android:无法使用CustomAdapter刷新Listview

我需要用新数据刷新列表视图.下面这个代码是用于获取数据OnCreateView是在FragmentActivity在第一时间.

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
                          savedInstanceState: Bundle?): View? {
        val url = "something"

        val request_queue = Volley.newRequestQueue(this.context)
        val stringRequest = StringRequest(Request.Method.GET, url,
                Response.Listener<String> { response ->
                    val pending_job = Gson().fromJson<ArrayList<HashMap<String, String>>>(
                            response.toString(),
                            object : TypeToken<ArrayList<HashMap<String, String>>>() {}.type
                    )
                    this@PlaceholderFragment.showList(rootView, R.id.pending_job_list, pending_job)

                    pending_job_list_layout.setOnRefreshListener(this)

                    request_queue.stop()
                }, Response.ErrorListener { error ->
            if (error.networkResponse != null) {
                Toast.makeText(this.context, error.networkResponse.statusCode.toString(), Toast.LENGTH_SHORT).show()
            }
            request_queue.stop()
        })
        request_queue.add(stringRequest)
}
Run Code Online (Sandbox Code Playgroud)

showList 是设置CustomAdapter的功能,即

fun showList(rootView: View, tab_id: Int, job_list: ArrayList<HashMap<String, String>>) {

    // custom …
Run Code Online (Sandbox Code Playgroud)

android custom-adapter kotlin android-listfragment android-volley

6
推荐指数
1
解决办法
205
查看次数