I want to do something like this (trello) Example, I mean the container that always appear in the end of created lists for creating a new one.
I have a recycler view, adapter and data from DataBase.
Adapter:
class BoardAdapter(private val boards: ArrayList<String>) : RecyclerView.Adapter<BoardAdapter.ViewHolder>() {
inner class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
val name = v.findViewById<TextView>(R.id.name)
val view = v
}
override fun getItemCount(): Int {
return boards.count()
}
override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
holder!!.name.text = boards[position]
val v = holder.view
v.setOnClickListener {
val intent = Intent(v.context, BoardActivity::class.java)
intent.putExtra("name", holder.name.text.toString())
v.context.startActivity(intent)
}
}
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent!!.context).inflate(R.layout.board_list_item,
parent, false)
return ViewHolder(v)
}
}
MainActivity
class MainActivity : AppCompatActivity() {
private lateinit var db: SQLiteDatabase
private lateinit var cursor: Cursor
private lateinit var adapter: BoardAdapter
private val boards = ArrayList<String>()
private val helper = DBHelper(this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
try {
db = helper.readableDatabase
cursor = db.query("BOARD", arrayOf("name"),
null, null, null, null, null)
while (cursor.moveToNext()) {
boards.add(cursor.getString(0))
}
cursor.close()
db.close()
} catch (e: SQLException) {
Log.e("SQL ERROR", e.message.toString())
Toast.makeText(this, R.string.db_error, Toast.LENGTH_SHORT).show()
}
adapter = BoardAdapter(boards)
recyclerView.layoutManager = GridLayoutManager(applicationContext, 2)
recyclerView.adapter = adapter
}
}
So, I have this: Picture. And I want to add in the end of this RecyclerView a custom view, which would be apply to add new board. How can I create this view from my layout and add this View to RecyclerView that my result will be something like this: Picture