I am trying to build a weather app using openweather api.I am trying to find the weather report of a city by searching the city name on the search bar.Have tried some solutions by everytime either the app crashes or search bar becomes unclickable. Search bar in xml file <androidx.appcompat.widget.SearchView android:id="@+id/searchView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="10dp"
android:background="@drawable/searchviewshape"
android:iconifiedByDefault="false"
android:queryHint="Search For A City"
android:searchIcon="@drawable/search"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Mainactivity function val searchView = binding.searchView
searchView.setOnQueryTextListener(object: SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
if (!query.isNullOrEmpty()) {
fetchWeatherData(query)
}
return true
}
override fun onQueryTextChange(newText: String?): Boolean {
// Handle text change if needed
return false
}
})
I tried to implement a function such that if i search for a city it will shows its weather report.But unfortunately it is not working .Even when in xml file when i set the search view as only <SearchView rather than <androidx.appcompat.widget.SearchView it throws an error.