【发布时间】:2022-01-22 16:07:18
【问题描述】:
我想填充 ListView 以显示特定值,该值将通过 Android Studio 中使用 Kotlin 的另一个类的数据作为标题。我知道如何填充 ListView,但我不确定如何获取“title”值并将其放入 ListView 这是我希望它看起来的一个示例:
用于填充 ListView 的类:
class SimpleViewListOfMoviesActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_view_list_of_movies)
val movies = SimpleMovieItem()
val test = arrayOf(movies.title)
val listAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, test)
movielist.adapter = listAdapter
}
}
里面有数据的类:
class SimpleMovieSampleData {
companion object{
var simpleMovieitemArray : ArrayList<SimpleMovieItem>
init {
simpleMovieitemArray = ArrayList<SimpleMovieItem>()
populateSimpleMovieItem()
}
fun populateSimpleMovieItem() : ArrayList<SimpleMovieItem>{
simpleMovieitemArray.add(
SimpleMovieItem("Super-assassin John Wick returns with a \$14 million price tag on his head and an army of bounty-hunting killers on his trail. After killing a member of the shadowy international assassin’s guild, the High Table, John Wick is excommunicado, but the world’s most ruthless hit men and women await his every turn.",
"August 23, 2019",
"English",
"John Wick: Chapter 3 - Parabellum ")
)
simpleMovieitemArray.add(
SimpleMovieItem("After faking his death, a tech billionaire recruits a team of international operatives for a bold and bloody mission to take down a brutal dictator.",
"December 13, 2019",
"English",
"6 Underground ")
)
simpleMovieitemArray.add(
SimpleMovieItem("After fighting his demons for decades, John Rambo now lives in peace on his family ranch in Arizona, but his rest is interrupted when Gabriela, the granddaughter of his housekeeper María, disappears after crossing the border into Mexico to meet her biological father. Rambo, who has become a true father figure for Gabriela over the years, undertakes a desperate and dangerous journey to find her.",
"December 17, 2019",
"English",
"Rambo: Last Blood ")
)
return simpleMovieitemArray
}
}
}
SimpleMovieItem
package com.nyp.sit.movieviewerbasic_starter
class SimpleMovieItem(
var overview: String? = null,
var release_date: String? = null, var original_langauge: String? = null,
var title: String? = null
) {
init {
this.overview = overview
this.release_date = release_date
this.original_langauge = original_langauge
this.title = title
}
}
【问题讨论】:
-
请尝试详细说明您想要实现的目标
标签: android android-studio kotlin