Я уже перенес все данные в json-файл в режим просмотра. Вместо этого я назначаю 4 кнопки в верхней части макета (я упоминал об этом ниже). Я хочу отфильтровать свой вид корзины по категории оценочной книги при нажатии на каждую кнопку. Я понятия не имею, чтобы сделать это.
Это мой класс модели
data class Model(
val author: Author,
val cover_page: String,
val description: String,
val file_size: Int,
val id: Int,
val isbn: String,
val language: String,
val name: String,
val no_of_pages: String,
val price: String,
val category: String
)
data class Author(
val name: String
)
Это мой адаптер
class RecycleAdapter(val context: Context) : RecyclerView.Adapter<RecycleAdapter.MyViewHolder>() {
var dataList : List<Model> = listOf()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.adapter_layout, parent, false)
return MyViewHolder(view)
}
override fun getItemCount(): Int {
return dataList.size
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
holder.name.text = dataList.get(position).name
holder.description = dataList.get(position).description
Glide.with(context).load(dataList.get(position).cover_page)
.apply(RequestOptions().centerCrop())
.into(holder.cover)
holder.author.text = dataList.get(position).author.name
holder.price.text = dataList.get(position).price
holder.language = dataList.get(position).language
holder.isbn = dataList.get(position).isbn
holder.numbOfPages = dataList.get(position).no_of_pages
holder.layoutPay.setOnClickListener {
val intent = Intent(context, BookDetails::class.java)
intent.putExtra("name", dataList.get(position).name)
intent.putExtra("description", dataList.get(position).description)
intent.putExtra("cover", dataList.get(position).cover_page)
intent.putExtra("author", dataList.get(position).author.name)
intent.putExtra("price", dataList.get(position).price)
intent.putExtra("language", dataList.get(position).language)
intent.putExtra("isbn", dataList.get(position).isbn)
intent.putExtra("pages_count", dataList.get(position).no_of_pages)
val options =
ActivityOptions.makeCustomAnimation(
context,
android.R.anim.fade_in,
android.R.anim.fade_out
)
context.startActivity(intent, options.toBundle())
}
}
fun setData(dataList: List<Model>) {
this.dataList = dataList
//Collections.sort(dataList)
notifyDataSetChanged()
}
class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val name: TextView = itemView.findViewById(R.id.txt_title)
val cover: ImageView = itemView.findViewById(R.id.img_cover)
val author: TextView = itemView.findViewById(R.id.txt_author)
val price: TextView = itemView.findViewById(R.id.txt_price)
lateinit var description: String
lateinit var language: String
lateinit var isbn: String
lateinit var numbOfPages: String
var layoutPay: ConstraintLayout = itemView.findViewById(R.id.layout_buy)
}
}
Это основное занятие
class MainActivity : AppCompatActivity() {
lateinit var recyclerView: RecyclerView
lateinit var recyclerAdapter: RecycleAdapter
private val ACTIVITY_NUM:Int = 0
//lateinit var dialog: Dialog
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//dialog.setContentView(R.layout.activity_detailview)
btn_feeds_all.setOnClickListener {
btn_feeds_all.setBackgroundResource(R.drawable.click_button)
btn_feeds_biographic.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_adventure.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_children.setBackgroundResource(R.drawable.non_click_button)
btn_cook.setBackgroundResource(R.drawable.non_click_button)
}
btn_feeds_biographic.setOnClickListener {
btn_feeds_biographic.setBackgroundResource(R.drawable.click_button)
btn_feeds_all.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_adventure.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_children.setBackgroundResource(R.drawable.non_click_button)
btn_cook.setBackgroundResource(R.drawable.non_click_button)
}
btn_feeds_adventure.setOnClickListener {
btn_feeds_adventure.setBackgroundResource(R.drawable.click_button)
btn_feeds_biographic.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_all.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_children.setBackgroundResource(R.drawable.non_click_button)
btn_cook.setBackgroundResource(R.drawable.non_click_button)
}
btn_feeds_children.setOnClickListener {
btn_feeds_children.setBackgroundResource(R.drawable.click_button)
btn_feeds_biographic.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_adventure.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_all.setBackgroundResource(R.drawable.non_click_button)
btn_cook.setBackgroundResource(R.drawable.non_click_button)
}
btn_cook.setOnClickListener {
btn_cook.setBackgroundResource(R.drawable.click_button)
btn_feeds_biographic.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_adventure.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_all.setBackgroundResource(R.drawable.non_click_button)
btn_feeds_children.setBackgroundResource(R.drawable.non_click_button)
}
btnLike.setOnClickListener {
}
recyclerView = findViewById(R.id.recyclerView)
recyclerAdapter = RecycleAdapter(this)
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recyclerView.adapter = recyclerAdapter
val apiInterface = JsonApi.create().getData()
apiInterface.enqueue(object : Callback<List<Model>> {
override fun onResponse(call: Call<List<Model>>?, response: Response<List<Model>>?) {
if (response?.body() != null)
recyclerAdapter.setData(response.body()!!)
}
override fun onFailure(call: Call<List<Model>>?, t: Throwable?) {
}
})
bottomNavigationView()
}
private fun bottomNavigationView() {
val bottomNavigationViewEx = findViewById<BottomNavigationViewEx>(R.id.bottomNaBar)
BottomNavigationViewHelper.enableNavigation(this, bottomNavigationViewEx)
val menu = bottomNavigationViewEx.getMenu()
val menuItem = menu.getItem(ACTIVITY_NUM)
menuItem.setChecked(true)
}
![enter image description here](https://i.stack.imgur.com/RVhIe.jpg)