In the Adapter method. i am able to print list elements in updateUsers(newUsers: List)
that means I am getting dataset in the Adapter, but none of the Adapter methods are getting called.
I have set the layout manager too.
I have breakpoints for All adapter methods onCreateViewHolder, onBindViewHolder. but control is not entering code block.
class MainActivity : AppCompatActivity() {
lateinit var viewModel: ListViewModel
private val usersAdapter = UserListAdapter(arrayListOf(),this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewModel = ViewModelProviders.of(this).get(ListViewModel::class.java)
viewModel.refresh()
usersList.apply {
layoutManager = LinearLayoutManager(this.context)
adapter = usersAdapter
}
usersList.adapter = usersAdapter
observeViewModel()
}
fun observeViewModel() {
viewModel.users.observe(this, Observer {
it?.let {
it.forEach {
Log.d("Each Item", it.toString());
}
loading_view.visibility = View.VISIBLE
usersAdapter.updateUsers(it)
}
})
viewModel.userLoadError.observe(this, Observer {
it?.let {
list_error.visibility = if (it) View.VISIBLE else View.GONE
}
})
viewModel.loading.observe(this, Observer {
it?.let {
loading_view.visibility = if (it) View.VISIBLE else View.GONE
if (it) {
list_error.visibility = View.GONE
usersList.visibility = View.GONE
}
}
})
}
}
class UserListAdapter(private var users: ArrayList<User>, private val context : Context) : RecyclerView.Adapter<UserListAdapter.UserViewHolder>() {
fun updateUsers(newUsers: List<User>) {
newUsers.forEach() {
Log.d("updateUsers", it.firstName)
}
users.clear()
users.addAll(newUsers)
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : UserViewHolder{
val layoutInflator = LayoutInflater.from(parent.context)
val view = layoutInflator.inflate(R.layout.item_layout,parent,false)
return UserViewHolder(view)
}
override fun getItemCount():Int {
return users.size
}
override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
holder.bind(users[position])
}
class UserViewHolder(view: View) : RecyclerView.ViewHolder(view) {
private val imageView = view.imageView
private val userName = view.name
private val userEmail = view.email
fun bind(country: User) {
userName.text = country.firstName + " " + country.lastName
userEmail.text = country.email
imageView.loadImage(country.avatar)
}
}
}
I am not exactly sure why your code is not working, here I have implemented using your code and it's working.
MainActivity
class MainActivity : AppCompatActivity() {
private lateinit var viewModel: ListViewModel
private val usersAdapter = UserListAdapter(arrayListOf(), this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewModel = ViewModelProviders.of(this).get(ListViewModel::class.java)
viewModel.refresh()
usersList.apply {
layoutManager = LinearLayoutManager(this.context,
RecyclerView.VERTICAL, false)
adapter = usersAdapter
}
// usersList.adapter = usersAdapter // Don't need, you already set the
// adapter above.
observeViewModel()
}
private fun observeViewModel() {
viewModel.users.observe(this, Observer {
it?.let {
it.forEach {
Log.d("Each Item", it.toString());
}
//loading_view.visibility = View.VISIBLE
usersAdapter.updateUsers(it)
}
})
// commented for simplicity
//viewModel.userLoadError.observe(this, Observer {
// it?.let {
//list_error.visibility = if (it) View.VISIBLE else View.GONE
// }
//})
// viewModel.loading.observe(this, Observer {
// it?.let {
// loading_view.visibility = if (it) View.VISIBLE else View.GONE
// if (it) {
// list_error.visibility = View.GONE
// usersList.visibility = View.GONE
// }
//
// }
// })
}
}
UserListAdapter
class UserListAdapter(private var users: ArrayList<User>, private val context : Context) : RecyclerView.Adapter<UserListAdapter.UserViewHolder>() {
fun updateUsers(newUsers: List<User>) {
newUsers.forEach() {
Log.d("updateUsers", it.firstName)
}
users.clear()
users.addAll(newUsers)
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : UserViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.item_layout,parent,false)
return UserViewHolder(view)
}
override fun getItemCount():Int {
return users.size
}
override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
holder.bind(users[position])
}
class UserViewHolder(view: View) : RecyclerView.ViewHolder(view) {
private val imageView = view.imageView
private val userName = view.name
private val userEmail = view.email
fun bind(country: User) {
userName.text = country.firstName + " " + country.lastName
userEmail.text = country.email
//imageView.loadImage(country.avatar)
}
}
}
ListViewModel
class ListViewModel: ViewModel() {
val users : MutableLiveData<List<User>> = MutableLiveData()
fun refresh() {
val userList = mutableListOf<User>()
userList.add(User(
"User1 First Name",
"User1 last Name",
"example#gmail.com"
))
userList.add(User(
"User2 First Name",
"User2 First Name",
"example#gmail.com"
))
userList.add(User(
"User3 First Name",
"User3 First Name",
"example#gmail.com"
))
userList.add(User(
"User4 First Name",
"User4 First Name",
"example#gmail.com"
))
userList.add(User(
"User5 First Name",
"User5 First Name",
"example#gmail.com"
))
userList.add(User(
"User6 First Name",
"User6 First Name",
"example#gmail.com"
))
users.value = userList
}
}
Hope this helps.
Related
I am using RecycleView in android studio. When data is coming from Firebase it is correct at first. Later, when I add 1 sms to the list of type List(), I get wrong data as a result.
For example:
If List is {1,2,3,4,5},
Add 6 to the list on the screen
The elements of List {1,2,3,4,5,6} should appear in this order.
In this case,
After the chase
List {1,2,3,4,5,1,2,3,4,5,6} is like this. After 1 update it works fine.
class ChatAdapter(var list:MutableList<Sms>,var context: Context):RecyclerView.Adapter<RecyclerView.ViewHolder>(){
companion object {
private const val ITEM_RECEIVE = 1
private const val ITEM_SENT = 2
}
private val shared by lazy {
SharedPref(context)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return if (viewType == 1) {
val view = LayoutInflater.from(context).inflate(R.layout.item_he_sms, parent, false)
ReceiveVewHolder(view)
}else{
val view = LayoutInflater.from(context).inflate(R.layout.item_my_sms, parent, false)
SentViewHolder(view)
}
}
override fun getItemViewType(position: Int): Int {
val currentMessage = list[position]
return if (currentMessage.emailAddress==shared.getEmail()){
ITEM_SENT
}else{
ITEM_RECEIVE
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (shared.getEmail()==list[position].emailAddress){
holder as SentViewHolder
holder.textView.text = list[position].smsText
}else{
holder as ReceiveVewHolder
holder.textView.text = list[position].smsText
if (list[position].gender=="Male"){
holder.imagePerson.setImageResource(R.drawable.male_avatar)
}else{
holder.imagePerson.setImageResource(R.drawable.female_avatar)
}
}
}
override fun getItemCount(): Int =list.size
inner class SentViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val textView: TextView = view.findViewById(R.id.my_message)
}
inner class ReceiveVewHolder(view: View) : RecyclerView.ViewHolder(view) {
val textView: TextView = view.findViewById(R.id.he_message)
val imagePerson:CircleImageView=view.findViewById(R.id.imagePerson)
}
}
Create this methode inside your Adapter :
fun updateList(list: List<Sms>){
this.list.clear()
this.list.addAll(list)
notifyDataSetChanged()
}
then call it from inside your observer method, it should resolve your problem.
Xato Firebase'dan getAllSms da, sendSms() usuli ishlayotganda, {1,2,3,4,5,1,2,3,4,5,6} ro'yxat sifatida qaytariladi. result.invoke ni bajarishdan oldin onDataChange-da list.clear ni bajarishingiz kerak.
override fun getAllSms(result: (UiState<ArrayList<Sms>>) -> Unit) {
CoroutineScope(Dispatchers.IO).launch {
val list = ArrayList<Sms>()
myRef.getReference("global")
.addValueEventListener(object :ValueEventListener{
override fun onDataChange(snapshot: DataSnapshot) {
list.clear()
snapshot.children.forEach {
val sms:Sms=it.getValue(Sms::class.java)!!
list.add(sms)
}
list.forEach {
Log.d("LLIISSTT", it.smsText)
}
result.invoke(UiState.Success(list))
}
override fun onCancelled(error: DatabaseError) {
result.invoke(UiState.Failure(error.message))
}
})
}
}
I can run this and I also got data appear but I got this warning on my Run terminal
"E/RecyclerView: No adapter attached; skipping layout
No adapter attached; skipping layout"
How can I solve this
class SpacedFragment : Fragment() {
private lateinit var kanjiViewModel : KanjiViewModel
private lateinit var spacedRecyclerAdapter : SpacedRecyclerAdapter
private lateinit var day1Adapter: SpacedRecyclerAdapter
private var _binding : FragmentSpacedBinding? = null
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View {
_binding = FragmentSpacedBinding.inflate(inflater,container,false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initUI()
}
private fun initUI() {
val dao = KanjiDatabase.getInstance(requireContext()).dao()
val repository = KanjiRepository(dao)
val factory = KanjiViewModelFactory(repository)
kanjiViewModel = ViewModelProvider(this,factory)[KanjiViewModel::class.java]
//adapter
spacedRecyclerAdapter = SpacedRecyclerAdapter()
day1Adapter = SpacedRecyclerAdapter()
//layoutManager
binding.spacedRecyclerview.layoutManager = GridLayoutManager(context,5)
binding.spacedRecyclerviewDay1.layoutManager = GridLayoutManager(context,5)
getData()
}
private fun getData() {
kanjiViewModel.kanjiList.observe(viewLifecycleOwner, { data ->
spacedRecyclerAdapter.submitList(data.filter { it.spacedstatus == 0 })
binding.spacedRecyclerview.adapter = spacedRecyclerAdapter
day1Adapter.submitList(data.filter { it.Japanese_Language_Proficiency_Test == 4 })
binding.spacedRecyclerviewDay1.adapter = day1Adapter
})
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
There is a sorting error in the relevant lines.
day1Adapter.submitList(data.filter { it.Japanese_Language_Proficiency_Test == 4 })
binding.spacedRecyclerviewDay1.adapter = day1Adapter
You should use submitlist after assigning adapter
set your adapter inside initUI function
private fun initUI() {
...code
spacedRecyclerAdapter = SpacedRecyclerAdapter()
binding.spacedRecyclerview.adapter = spacedRecyclerAdapter
day1Adapter = SpacedRecyclerAdapter()
binding.spacedRecyclerviewDay1.adapter = day1Adapter
...code
getData()
}
private fun getData() {
kanjiViewModel.kanjiList.observe(viewLifecycleOwner, { data ->
spacedRecyclerAdapter.submitList(data.filter { it.spacedstatus == 0 })
day1Adapter.submitList(data.filter { it.Japanese_Language_Proficiency_Test == 4 })
})
}
I have a recyclerview where view type is edittext and on value entered of the edittext, other edittext values should be added with current value.
value entered in edittext item 1 of recyclerview and value entered in edittext item 2 should be the sum in the edittext item 3 which is not editable.
So in below code, the type 'Edittext' is used to identify that these edittext have text watchers and on change of these editttext values, the values of calculations be set in else part.
How to update the data in else code when i am updating the text in editable edittext. this is my code below.
Anyone having solution,
// enter code here
class ProfileDataSubAdapter(
val context: Context,
var repeatedDataList: RealmList<EntityDetails>
) : RecyclerView.Adapter<ProfileDataSubAdapter.DataAdapterViewHolder>() {
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): DataAdapterViewHolder {
val layout = when (viewType) {
TYPE_EDITTEXT -> R.layout.item_edittext
TYPE_SPINNER -> R.layout.item_spinner
TYPE_CALCULATE -> R.layout.item_edittext
else -> throw IllegalArgumentException("Invalid view type")
}
val view = LayoutInflater
.from(context)
.inflate(layout, parent, false)
return DataAdapterViewHolder(view)
}
override fun onBindViewHolder(holder: DataAdapterViewHolder, position: Int) {
holder.bind(repeatedDataList[position], context, position)
}
fun getRepeatedList(): RealmList<EntityDetails>? {
repeatedDataList.forEach {
if (it.ValueType.equals("EditText") && it.UserEnterValue?.isNullOrEmpty()!!) {
Toast.makeText(context, "Field ${it.EntityName} is empty", Toast.LENGTH_LONG).show()
return null;
}
}
return repeatedDataList
}
override fun getItemCount(): Int = repeatedDataList.size
override fun getItemViewType(position: Int): Int {
if (repeatedDataList[position]?.ValueType == "EditText") {
return TYPE_EDITTEXT
} else if (repeatedDataList[position]?.ValueType == "RadioButton") {
return TYPE_SPINNER
} else
return TYPE_CALCULATE
}
companion object {
private const val TYPE_EDITTEXT = 0
private const val TYPE_SPINNER = 1
private const val TYPE_CALCULATE = 3
}
inner class DataAdapterViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindEdittextData(item: EntityDetails, position: Int) {
//Do your view assignment here from the data model
itemView.findViewById<TextView>(R.id.tv_edit_text_label)?.text = item.EntityName
val content = itemView.findViewById<EditText>(R.id.et_content)
if (item.UserEnterValue?.isNotEmpty()!!) {
content.setText(item.UserEnterValue)
}
//if type is edittext then set text watchers here
if (item.ValueType == "EditText") {
content.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) {
repeatedDataList[position]?.UserEnterValue = p0.toString()
}
override fun afterTextChanged(p0: Editable?) {
}
})
}
// else if type is calculation set the total here
else {
content.setInputType(InputType.TYPE_NULL)
}
}
fun bindSpinnerData(item: EntityDetails, context: Context) {
//Do your view assignment here from the data model
itemView.findViewById<TextView>(R.id.tv_spinner_label)?.text = item.EntityName
val spinner = itemView.findViewById<Spinner>(R.id.spinner_content)
spinner.adapter = ArrayAdapter<String>(
context,
R.layout.row_spinner,
R.id.txt_content,
item.Values?.map { it.Value } as MutableList<String>
)
// spnr_house.setSelection(getIndexSpinner(spnr_house, noOfYearsInCurrentHouse?.trim()))
spinner.setSelection(item.Values!!.indexOfFirst {
it.IsSelected == true
}, false)
// spinner.setSelection()
spinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(view: AdapterView<*>?) {
}
override fun onItemSelected(
parentView: AdapterView<*>?,
selectedView: View?,
pos: Int,
id: Long
) {
val selectedItem =
spinner.getItemAtPosition(pos)
.toString()
if (selectedItem != "Select") {
item.Values?.find { it.Value == selectedItem }?.IsSelected =
true
val list = item.Values?.filter { it.Value != selectedItem }
list?.forEach { it.IsSelected = false }
}
}
}
}
fun bind(
dataModel: EntityDetails?,
context: Context,
position: Int
) {
if (dataModel?.ValueType == "EditText" || dataModel?.ValueType == "Calculation")
bindEdittextData(dataModel, position)
else if (dataModel?.ValueType == "RadioButton")
bindSpinnerData(dataModel, context)
}
}
}
//end code
I'm assigning a value to lateinit varable in my first function and I want to access same value in my second function but gives me an error UninitializedPropertyAccessException. I know it is because of variable scope. My question is how can i access this value?
Here is my lateinit variables
lateinit var area:String
lateinit var zipcode:String
Here is my first function
fun showSearchDialog(view: View) {
val dialog = context?.let { Dialog(it) }
dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog?.setCancelable(true)
dialog?.setContentView(R.layout.alertdialog_search_layout)
//Initializing the views of the dialog.
val postalCode: TextInputEditText? = dialog?.findViewById(R.id.et_zip_code)
val sliderArea: Slider? = dialog?.findViewById(R.id.slider_area)
val searchButton: Button? = dialog?.findViewById(R.id.search_btn)
searchButton?.setOnClickListener {
if (sliderArea != null) {
area = sliderArea.value.toString()
}
zipcode = postalCode?.text.toString()
val postCodeUpperCase = postalCode?.text.toString().toUpperCase(Locale.ROOT)
if (zipcode.isEmpty()) {
postalCode?.error = "Please enter your post code"
postalCode?.requestFocus()
} else if (isValidZipCode(postCodeUpperCase)) {
postalCode?.error = "Please enter valid post code"
postalCode?.requestFocus()
} else {
if (isNetworkAvailable(requireContext())) {
viewModel.getSkipFilterList(zipcode, area)
Toast.makeText(context, "Valid postal code is = $zipcode", Toast.LENGTH_LONG).show()
}
else {
showAlertDialog(getString(R.string.no_internet))
}
}
//dialog.dismiss()
}
dialog?.show()
Here is my second Function
override fun inOnCreateView(mRootView: ViewGroup, savedInstanceState: Bundle?) {
val homeActivity = activity as HomeNavHostActivity
homeActivity.toolbar_id?.visibility = View.VISIBLE
homeActivity.toolbar_search_icon_id.visibility = View.VISIBLE
homeActivity.toolbar_add_icon_id.visibility = View.GONE
homeActivity.home_view_layout?.visibility = View.VISIBLE
homeActivity.bottom_layout?.visibility = View.VISIBLE
homeActivity.toolbar_title_tv.text = "Home"
homeActivity.toolbar_search_icon_id.setOnClickListener() {
showSearchDialog(mRootView)
}
homeActivity.cancel_text.setOnClickListener() {
homeActivity.search_layout.visibility = View.GONE
homeActivity.toolbar_title_tv.visibility = View.VISIBLE
homeActivity.search_view?.setQuery("", false)
homeActivity.search_view?.clearFocus()
}
val dialogHelper by inject<MaterialDialogHelper>()
setupProgressDialog(viewModel.showHideProgressDialog, dialogHelper)
if (isNetworkAvailable(requireContext())) {
viewModel.getSkipFilterList(zipcode, area)
// viewModel.getSkipHomeData()
} else {
showAlertDialog(getString(R.string.no_internet))
}
attachViewModel()
}
I am a newbie on android.
I already made an activity that shows all my contact list and number inside Linear Layout. How can I make phone call using intent after I click the Linear Layout?
I don't know where to put the setOnclickListener in my code. So here I share all of the source-code.
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical">
<TextView
android:id="#+id/itemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="Nama : "
style="#style/Base.TextAppearance.AppCompat.Headline"/>
<TextView
android:id="#+id/itemNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="Nomor HP : "
style="#style/Base.TextAppearance.AppCompat.Body2"/>
</LinearLayout>
MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
showDetail.setOnClickListener {
var myDetailIntent = Intent(this, DetailActivity::class.java)
startActivity(myDetailIntent)
}
doAsync {
Thread.sleep(5000L)
uiThread {
showNotivy();
}
}
}
private fun showNotivy() {
val notfyDetailIntent = Intent(this#MainActivity,
DetailActivity::class.java)
val myPendingIntent = TaskStackBuilder.create(this)
.addParentStack(DetailActivity::class.java)
.addNextIntent(notfyDetailIntent)
.getPendingIntent(110, PendingIntent.FLAG_UPDATE_CURRENT)
val myNotfyManager = this.getSystemService(android.content.Context.NOTIFICATION_SERVICE) as NotificationManager
val myBuilder = NotificationCompat.Builder(this)
.setContentTitle("Show Detail Contact")
.setContentText("Click Me !")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(myPendingIntent)
.setAutoCancel(true)
myNotfyManager.notify(1101, myBuilder.build())
}
}
DetailActivity.kt
class DetailActivity : AppCompatActivity(), LoaderManager.LoaderCallbacks<Cursor> {
var DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME
var NUMBER = ContactsContract.CommonDataKinds.Phone.NUMBER
val myListContact : MutableList<myContact> = ArrayList();
override fun onCreateLoader(p0: Int, p1: Bundle?): Loader<Cursor> {
val MyContentUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
val myProjection = arrayOf(DISPLAY_NAME, NUMBER)
return CursorLoader(this, MyContentUri, myProjection, null, null, DISPLAY_NAME+ " ASC")
}
override fun onLoadFinished(p0: Loader<Cursor>, p1: Cursor?) {
myListContact.clear()
if (p1!=null) {
p1.moveToFirst()
while(!p1.isAfterLast()) {
myListContact.add(myContact(nama = p1.getString(p1.getColumnIndex(DISPLAY_NAME)),nomorHp = p1.getString(p1.getColumnIndex(NUMBER))))
p1.moveToNext()
}
}
val contactAdapter = myAdapterRecyView(myListContact)
myRecyView.apply {
layoutManager = LinearLayoutManager(this#DetailActivity)
adapter = contactAdapter
}
}
override fun onLoaderReset(p0: Loader<Cursor>) {
val contactAdapter = myAdapterRecyView(myListContact)
myRecyView.apply {
layoutManager = LinearLayoutManager(this#DetailActivity)
adapter = contactAdapter
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_detail)
LoaderManager.getInstance(this).initLoader(1, null, this)
}
}
myAdapterRecyView.kt
class myAdapterRecyView(private val contact : List<myContact>): RecyclerView.Adapter<myHolder>() {
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): myHolder {
return myHolder(LayoutInflater.from(p0.context)
.inflate(R.layout.layout_recy_view,p0,false))
}
override fun getItemCount(): Int = contact.size
override fun onBindViewHolder(p0: myHolder, p1: Int) {
p0.bindContact(contact[p1])
}
}
class myHolder(view: View):RecyclerView.ViewHolder(view) {
private val contactName = view.itemName
private val contactNumber = view.itemNumber
fun bindContact(tmp: myContact) {
contactName.text = "${contactName.text} ${tmp.nama}"
contactNumber.text = "${contactNumber.text} ${tmp.nomorHp}"
}
}
class myHolder(view: View):RecyclerView.ViewHolder(view) {
private val contactName = view.itemName
private val contactNumber = view.itemNumber
fun bindContact(tmp: myContact) {
contactName.text = "${contactName.text} ${tmp.nama}"
contactNumber.text = "${contactNumber.text} ${tmp.nomorHp}"
}
}
myContact.kt
class myContact (
val nama : String,
val nomorHp : String
)
You can put yout click action inside the onBind in recycler view adapter.
class myHolder(view: View):RecyclerView.ViewHolder(view) {
private val contactName = view.itemName
private val contactNumber = view.itemNumber
fun bindContact(tmp: myContact) {
contactName.text = "${contactName.text} ${tmp.nama}"
contactNumber.text = "${contactNumber.text} ${tmp.nomorHp}"
view.setOnClickListener {
// YOUR ACTION HERE.
}
}
}