Android Kotlin


#1

i have lists of arrays in recyclerview , each array contains 4 items 2 textviews and 2 edittext i need send the data once editing is done to server using retrofit and get the response also each array have unique id also . what should i code it. please help me.


#2

Paste the code you have tried or narrow down the problem.
At the moment, this question looks like: I want you to work for me…

What did you try between the posting of the former question and this question?
I recommend you to write it down in the other topic, as that question is the better one.


#3

New Text Document.doc (5.4 KB)


#4

Still this thing is not working some kind of error is coming .

Can anyone please help me out in this case . Most Welcome


#5

Still i didn’t find any solution for this except that the position of that Edit-Text can be taken from the function that contains 3 overriding methods 1- before text changed 2- on text Changed and 3- after text changed .
but after that i am not able to figure out how to use that position to send the updated data and receive the updated data .
this function is written in View Holder inner class in adapter.


#6

To be told truth I don’t think this question is the question about Kotlin, it’s more about Android platform.
Anyway you can create some interface with methods that will send your modified arrays to server. Implement it in your fragment/activity and hold item of this fragment as listener within the your adapter for recyclerVIew. Also you can create some counter for modifications in ViewHolder and do it trigerred after changes of focus in EditText

class Adapter(var listener: OnSendItems): RecyclerView.Adapter<Adapter.ViewHolder> {
var items = mutableLististOf<Any>()
// do other stuff 

inner class ViewHolder {
    fun bindView(item: Any) {
      // bind views
      editText.addTextChangedListener(object : TextWatcher {
        override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
        }

        override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
        }
        override fun afterTextChanged(editable: Editable?) {
              listener.saveToServer(adapterPosition, items[adapterPosition])
        }
      })
     }
   }
}

interface OnSendItems {
  fun sendToServer(position: Int, vararg items: Any?)
}
class Fragment: Fragment, OnSendItems {
      fun createAdapter() {
         var adapter = Adapter()
        adapter.items.addAll(listOf(1,2,3))
        recyclerView.adapter = adapter
     }

  override fun saveToServer(position: Int, vararg items: Any?) {
      // make request with received data
  }
}