我有一个Observable<<List<Foo>> getFoo()从Retrofit服务创建的,在调用该
.getFoo()方法后,我需要与多个订阅者共享它..share()但是,调用该方法会导致重新执行网络呼叫.重播运算符也不起作用.我知道可能有一个潜在的解决方案.cache(),但我不知道为什么会出现这种行为.
// Create an instance of our GitHub API interface.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
// Create a call instance for looking up Retrofit contributors.
Observable<List<Contributor>> testObservable = retrofit
.create(GitHub.class)
.contributors("square", "retrofit")
.share();
Subscription subscription1 = testObservable
.subscribe(new Subscriber<List<Contributor>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable throwable) {
}
@Override
public void onNext(List<Contributor> contributors) {
System.out.println(contributors);
}
});
Subscription subscription2 = testObservable
.subscribe(new …Run Code Online (Sandbox Code Playgroud) 奇怪的是,我CustomBaseAdapter正在为需要充气的物品返回错误的位置,等适配器会在行上显示错误的数据类型!
虽然我正在使用该ViewHolder模式,但我的ListView layout_height设置为match_parent并且我找到的每种可能的方式,以确保ListView项目的稳定性,已经实现,CustomBaseAdapter似乎没有响应它.
getView()方法
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
mItemView = convertView;
if (convertView == null) {
mItemView = mInflater.inflate(R.layout.layout_listview_row, parent, false);
holder = new ViewHolder();
//setting up the Views
mItemView.setTag(holder);
} else {
holder = (ViewHolder) mItemView.getTag();
}
//Getting the item
final MyItem item = getItem(position);
//Doing some checks on my item and then display the appropriate data.
//By saying checks …Run Code Online (Sandbox Code Playgroud)