如何在Activity中设置下一个滑动器

时间:2019-01-15 11:00:29

标签: java android kotlin

我正在创建阿拉伯字母android应用程序。 在Recyclerview的MainActivity中,我有28个字母列表。单击项目,然后转到DetailActivity

 class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_detail)
    val name = getIntent().getStringExtra("NAME")
    val context = getIntent().getStringExtra("CONTEXT")
    val image_link = getIntent().getIntExtra("IMAGE", R.mipmap.third)
    initToolbar(name)
    initCollapsingToolbarLayout(context, image_link)

    recyclerView.apply {
        layoutManager = GridLayoutManager(this@MainActivity, 3)
        adapter = ItemAlphabetAdapter(alphabets)
    }

}.......

MainActivity view photo

这是我的字母适配器

class ItemAlphabetAdapter(
private val alphabets: ArrayList<ItemAlphabet>
) : RecyclerView.Adapter<ItemAlphabetAdapter.ViewHolder>() {


override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
    val view = LayoutInflater.from(parent.context).inflate(R.layout.alphabet_item, parent, false)
    val holder = ViewHolder(view)
    Log.d("ItemAlphabetAdapter", "${alphabets.size}")
    view.setOnClickListener {
        val intent = Intent(parent.context, ItemAlphabetDetailActivity::class.java)
        intent.putExtra("NAME", alphabets[holder.adapterPosition].name)
        intent.putExtra("CONTEXT", alphabets[holder.adapterPosition].context)
        intent.putExtra("IMAGE", alphabets[holder.adapterPosition].image)
        intent.putExtra("SOUND", alphabets[holder.adapterPosition].sound)
        parent.context.startActivity(intent)
    }
    return holder
}

在ItemAlphabetDetailActivity中,我使用getIntent()获取数据。 对于DetailActivity,我如何添加滑动器以转到下一个或上一个元素?

DetailActivity View photo

0 个答案:

没有答案