I am new to Kotlin. I am developing an app using Amadeus API. I am using the following code and get result in text view.
I do not know how to create custom adapter and get the result in list view. My problem is linking custom adapter and getting the result in list view. Can some one help me with some code so that I can understand. I am getting the fare in EURO. Please also let me know how to get the fare in Indian Rupees and US Dollars. Thank you in advance.
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.*
import com.amadeus.android.ApiResult
class ResultActivity : AppCompatActivity() {
private lateinit var result: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.result)
result = findViewById(R.id.result)
val my_data: MutableLiveData<String> by lazy {
MutableLiveData<String>()}
val dataObserver = Observer<String> { new_data ->
result.text = new_data }
my_data.observe(this, dataObserver)
val job = SupervisorJob()
val scope = CoroutineScope(Dispatchers.Main + job)
scope.launch {
when (val flightDestinations = SampleApplication.amadeus.shopping.flightDestinations.get(origin = "MAD")) {
is ApiResult.Success -> {
//Log.d("Result", "${result.data}")
my_data.value = "${flightDestinations.data}"
}
is ApiResult.Error -> {
// Handle your error
}
}
}
}
}