首页 > 解决方案 > 如何将此数组列表放入此方法中?

问题描述

如何把这个ArrayList放在这个方法中?有人可以告诉我如何通过ArrayList这种方法传递它吗?我添加了所有片段代码有人可以指导我吗?我尝试了几种方法来通过这个ArrayList但没有成功总是保持空白片段谢谢

数组列表

<string-array name="object_types">

方法

private var issues: ArrayList<Issue> = ArrayList()

  private fun getIssues() {
       val stream = resources.openRawResource(R.raw.markers)
        val inputString = stream.bufferedReader().use {
            it.readText()
        }
        val klaxon = Klaxon()
        JsonReader(StringReader(inputString)).use { reader -> // requires kotlin > 1.2 !!
         reader.beginArray {
              while (reader.hasNext()) { // requires "[]" array and not {"something": []}
                    val issue = klaxon.parse<Issue>(reader)
                   this.issues!!.add(issue!!)
               }          }
        }
        this.issues = Utils.markers
    }

GalleryFragment
所有片段代码如下

class GalleryFragment : Fragment(), IssueItemOnClickListener {

    private var productsRecyclerView: RecyclerView? = null
    private var recyclerAdapter: IssueRecyclerViewAdapter? = null
    private var recyclerLayoutManager: RecyclerView.LayoutManager? = null
    private var issues: ArrayList<Issue> = ArrayList()

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_gallery, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        getIssues()

        this.productsRecyclerView = view.findViewById(R.id.issue_list_recycler_view) as RecyclerView
        this.productsRecyclerView!!.setHasFixedSize(true)

        // use a grid layout manager -> 2 columns
        this.recyclerLayoutManager = GridLayoutManager(context, 2) as RecyclerView.LayoutManager?
        this.productsRecyclerView!!.layoutManager = this.recyclerLayoutManager

        this.recyclerAdapter = IssueRecyclerViewAdapter(this.issues, this)
        this.productsRecyclerView!!.adapter = recyclerAdapter
    }
    override fun onIssueItemClick(pos: Int, issue: Issue) {
        val args = Bundle()
        val detailsFragment = IssueDetailsFragment()
        args.putDouble("lat", issue.lat)
        args.putDouble("lng", issue.lng)
        args.putString("description", issue.description)
        args.putString("name", issue.name)
        args.putString("type", issue.type)
        args.putString("imgUrl", issue.imgUrl)
        detailsFragment.arguments = args

        val ft = activity!!.supportFragmentManager.beginTransaction()
        ft.replace(R.id.main_fragment_content, detailsFragment)
                .setTransition(android.app.FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                .addToBackStack(null).commit()
    }
    private fun getIssues() {
        val stream = resources.openRawResource(R.raw.markers)
        val inputString = stream.bufferedReader().use {
            it.readText()
       }
       val klaxon = Klaxon()
       JsonReader(StringReader(inputString)).use { reader -> // requires kotlin > 1.2 !!
            reader.beginArray {
                while (reader.hasNext()) { // requires "[]" array and not {"something": []}
                   val issue = klaxon.parse<Issue>(reader)
                    this.issues!!.add(issue!!)
                }
            }
        }
        this.issues = Utils.markers
    }
}

标签: kotlin

解决方案


[解决了]

改变

private var issues: ArrayList<Issue> = ArrayList()

private var object_values: ArrayList<Issue> = ArrayList()

推荐阅读