我正在使用RxJava和Retrofit.我的基本要求是,我想链接两个api调用,这将被一个接一个地调用.从第一个api收到的响应在调用第二个api时用作输入.在互联网上阅读了一些东西之后我习惯了flatmap来实现这个目标.在执行此操作时,我正在显示装载器.有时它运行顺利但在某些情况下这个装载机冻结.DDMS显示"跳过300帧,应用程序可能在其主线程上做了太多工作"的日志.我怀疑我的一个网络调用正在主线程上运行.我无法弄清楚如何链接这两个调用,以便可以在后台顺利调用它们而不会妨碍我的主线程.任何帮助是极大的赞赏 .提前谢谢这是我到目前为止所尝试的
private CompositeSubscription mSubscriptions = new CompositeSubscription();
Subscription subscription = Observable.just(getAddress())
.subscribeOn(Schedulers.newThread())
.flatMap(address -> mPlatformApi.secondWebService(address.getLatitude(),address.getLongitude())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(modelTwo ->
{
//updating My ui
}, throwable -> {
//Error Handling
});
mSubscriptions.add(subscription);
private android.location.Address getAddress(){
String addressString = "";//some Address String
Geocoder coder = new Geocoder(getActivity());
android.location.Address address=null;
try {
ArrayList<android.location.Address> addressList = (ArrayList<android.location.Address>) coder.getFromLocationName(addressString, 1);
if(addressList !=null && addressList.size()>0) {
address = addressList.get(0);
} else {
}
} catch (IOException e) {
e.printStackTrace();
}
return address;
}
//My Retrofit call …Run Code Online (Sandbox Code Playgroud) 我正在尝试将选择器应用到我的列表视图,它是一个自定义列表视图,我尝试了很多选项,但没有任何工作.任何帮助将不胜感激.我附上了我的代码.提前致谢
selector_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/faintblue" />
<item android:state_focused="true" android:drawable="@drawable/yellow" />
</selector>
Run Code Online (Sandbox Code Playgroud)
layout_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<ListView
android:id="@+id/lvChatList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/rlHeader"
android:background="@drawable/selector_expandable_listview"
android:listSelector="@drawable/selector_expandable_listview" >
</ListView>
<TextView
android:id="@+id/tvNoChats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No Chats"
android:visibility="gone" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
黄色背景效果有效发生但蓝色效果没有发生,请提前帮助谢谢