Skip to content

Instantly share code, notes, and snippets.

@ngima
Created June 9, 2021 04:56

Revisions

  1. ngima created this gist Jun 9, 2021.
    22 changes: 22 additions & 0 deletions RecyclerView.Adapter.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    //radapter
    class $adapter$ : androidx.recyclerview.widget.RecyclerView.Adapter<$adapter$.ViewHolder>() {

    var data: MutableList<$model$> = mutableListOf()
    set(value) {
    field = value
    notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: android.view.ViewGroup, viewType: Int): ViewHolder =
    ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.$item_layout_id$, parent, false))

    override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(data[position])

    override fun getItemCount() = data.size

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    fun bind(item: $model$) = with(itemView) {
    // TODO: Bind the data with View
    }
    }
    }
    10 changes: 10 additions & 0 deletions Snack.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    //sback
    com.google.android.material.snackbar.Snackbar.make($parentlayout$, "$message$", Snackbar.LENGTH_LONG)
    .show()

    //snackaction
    com.google.android.material.snackbar.Snackbar.make($parentlayout$, "$message$", Snackbar.LENGTH_LONG)
    .setAction("$actionname$", {view->

    }
    .show()