android - add action in RecyclerView -


i have recyclerview , cardview

cardview have checkbox

i want check if checkbox check or no in each item in recyclerview

and want delete item if checkbox not checked

any method me ?

this xml :

    <android.support.v7.widget.recyclerview         android:id="@+id/rec"         android:layout_width="match_parent"         android:layout_height="match_parent">       </android.support.v7.widget.recyclerview> 

and adapter class :

  class adapter( private val cartlist: arraylist<card>,val context: context): recyclerview.adapter<adapter.myviewholder>() {   override fun oncreateviewholder(viewgroup: viewgroup, viewtype: int): myviewholder {      val view = layoutinflater.from(viewgroup.context).inflate(r.layout.tkt_all_station, viewgroup, false)     return myviewholder(view) }   override fun onbindviewholder(holder: myviewholder, position: int) {       val cart:card = cartlist[position]      holder.title.text = cart.station     holder.msg.text = cart.x.tostring()     holder.date.text = cart.y.tostring()   }   override fun getitemcount(): int {      return cartlist.size  }   class myviewholder(itemview:view) : recyclerview.viewholder(itemview) {      var title = itemview.findviewbyid<textview>(r.id.stationnmae) textview     var msg = itemview.findviewbyid<textview>(r.id.xall) textview     var date = itemview.findviewbyid<textview>(r.id.yall) textview    }} 

and main activity :

 class all_station : appcompatactivity() {   override fun oncreate(savedinstancestate: bundle?) {     super.oncreate(savedinstancestate)     setcontentview(r.layout.activity_all__station)     rec.layoutmanager= linearlayoutmanager(this, linearlayout.vertical,false)     var db = firebasedatabase.getinstance().getreference()     var listofstation = arraylist<card>()        db.child("latitude , longitude").addvalueeventlistener(object :valueeventlistener{           override fun ondatachange(p0: datasnapshot?) {               var nour = p0!!.value hashmap<string,any>    (key in nour.keys){  var data = nour[key]as hashmap<string,any>  listofstation.add(card(           data["jop"] string, data["latitude"] string, data["longitude"] string  ))             }             var adapter = adapter(listofstation ,this@all_station )            rec.adapter = adapter       }          override fun oncancelled(p0: databaseerror?) {          }       }) } 

...............................................................................


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -