Я пытаюсь кодировать Recyclerview с помощью функции двух блесен. Основные цели - показать результат фильтрации по двум счетчикам. Например, существует 7 списков, каждый из которых имеет определенную дисциплину, такую как «Архитектурный», «Механический», «Электрический» и т. Д., И данные о этажах, такие как 1, 2, 3, 4 ..
Так , Я сделал код, подобный этому
Это адаптер из перечня переработчиков.
class ProjectFilesModel(val fileName: String, val ctype: String, val floor: Int)
class FileDataViewHolder(override val containerView: View) : RecyclerView.ViewHolder(containerView), LayoutContainer
class FileDataAdapter(val fileList: List<ProjectFilesModel>) :
RecyclerView.Adapter<FileDataViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FileDataViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.filtered_file, parent, false)
return FileDataViewHolder(view)
}
override fun getItemCount(): Int {
return fileList.count()
}
override fun onBindViewHolder(holder: FileDataViewHolder, position: Int) {
holder.containerView.fileNameLayout.text = fileList[position].fileName
holder.containerView.ctypeLayout.text = fileList[position].ctype
holder.containerView.floorLayout.text = "${fileList[position].floor}floor"
}
}
И это основное занятие;
class MainActivity : AppCompatActivity() {
//ctype option array
var ctypeArray =
arrayOf("All", "Architectural", "Mechanical", "Electrical", "Structural", "Civil")
var ctypeOptionAdapter: ArrayAdapter<String>? = null
//floor option arry
var floorArray = arrayOf(1, 2, 3)
var floorOptionAdapter: ArrayAdapter<Int>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ctypeOptionAdapter =
ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, ctypeArray)
ctypeOption.adapter = ctypeOptionAdapter
floorOptionAdapter =
ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, floorArray)
floorOption.adapter = floorOptionAdapter
ctypeOption.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {}
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
if (position >= 0 && position < floorArray.size) {
getSelectedListData(position)
} else {
Toast.makeText(
this@MainActivity,
"Selected Category Does not Exist!",
Toast.LENGTH_SHORT
).show()
}
}
}
val fileArrayList = arrayListOf(
ProjectFilesModel("A_file", "Architectural", 1),
ProjectFilesModel("B_file", "Mechanical", 1),
ProjectFilesModel("C_file", "Electrical", 2),
ProjectFilesModel("D_file", "Structural", 2),
ProjectFilesModel("E_file", "Architectural", 2),
ProjectFilesModel("F_file", "Mechanical", 3),
ProjectFilesModel("G_file", "Electrical", 3)
)
val fileArrayAdapter = FileDataAdapter(fileArrayList)
filteredListView.adapter = fileArrayAdapter
filteredListView.layoutManager = LinearLayoutManager(this)
}
fun getSelectedListData(position: Int) {
/* I'm stuck from here..*/
}
}
Я не уверен, что я иду в правильном направлении ..
Пожалуйста, дайте мне несколько советов!