I am making an app (ehealth portal) in Android Studio using Kotlin language and in that app, the user should be able to book an appointment choosing date/time/doctor's name from a dropdown list, and once they push the "book a date" button a confirmation screen appears that has the values of the dropdown lists (date/time/doctor's name) passed into a confirmation text confirmation activity instance booking a dated interface.
CalendarFragment.kt
package com.example.mydoctor
import...
class CalendarFragment : Fragment() {
private lateinit var binding: FragmentCalendarBinding1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
super.onCreate(savedInstanceState)
binding = FragmentCalendarBinding1.inflate(layoutInflater)
val itemsDates = resources.getStringArray(R.array.dates)
val adapterDate = ArrayAdapter(requireContext(), list_dates, itemsDates)
binding.autocompleteTextViewDateDropdown.setAdapter(adapterDate)
val itemsTimes = resources.getStringArray(R.array.times)
val adapterTime = ArrayAdapter(requireContext(), list_times, itemsTimes)
binding.autocompleteTextViewTimeDropdown.setAdapter(adapterTime)
binding.bookADateButton.setOnClickListener {
val intent = Intent(requireContext(),ConfirmationActivity::class.java)
intent.putExtra("Confirmation","Confirmation Value")
startActivity(intent)
}
return binding.root
}
}
ConfirmationActivity.kt
package com.example.mydoctor
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log
class ConfirmationActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_confirmation)
val value = intent.getStringExtra("Confirmation").toString()
Log.d("conf","Values is: ${value}")
}
}
How can I go about that? I know I have to use getExtra() or getStringExtra() but how should I actually get the value from the calendar fragment?
EDIT:
I tried changing the setOnClickListener in the CalendarFragment.kt as follows but it does not seem to work storing the value:
binding.bookADateButton.setOnClickListener {
(date_dropdown.getEditText() as AutoCompleteTextView).onItemClickListener =
OnItemClickListener {
adapterView, view, position, _ ->
val selectedValue: String? = adapterDate.getItem(position)
}
val intent = Intent(requireContext(),ConfirmationActivity::class.java)
intent.putExtra("Confirmation","Confirmation Value")
startActivity(intent)
}