I have a simple question even though I can’t answer it myself.
I have a class which is my Api class with a single which expect a string query parameeter:
public Single<List<Products>> searchProducts(){
return api.searchProducts();
}
and I have a Activity class with the data that I need which is searchEt:
String searchData = searchEt.toString();
my question is that how can I pass this searchEt to my Api class which need the String query?
api.searchProducts();
I tried to use interface but I’ve got confused.
>Solution :
In the Api class:
public Single<List<Products>> searchProducts(String query){
return api.searchProducts(query);
}
In the Activity class:
String searchData = searchEt.getText().toString();
api.searchProducts(searchData)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SingleObserver<List<Products>>() {
@Override
public void onSubscribe(Disposable d) {
// Handle the subscription
}
@Override
public void onSuccess(List<Products> products) {
// Handle the successful response
}
@Override
public void onError(Throwable e) {
// Handle the error
}
});
In the updated code, the searchProducts method in the Api class now accepts a query parameter of type String. You can pass the searchData value from your Activity class to this method when calling it.