I am new to Reactive so go easy on me, but I am trying to replace an async task that is currently run on text changes for an auto suggest function. Below is where I am at with my RX:
rest.getMemberList(etSearch.getText().toString())//rest interface
.subscribeOn(Schedulers.io())
.observeOn(RxAndroidSchedulers.mainThread())
.subscribe(new Action1<List<Member>>() {
@Override
public void call(List<Member> results) {
ListView ResultsListView = (ListView) findViewById(R.id.list);
MemberAdapter = new ResultRowAdapter(mContext, getLayoutInflater());
MemberAdapter.setMemberList(results);
ResultsListView.setAdapter(MemberAdapter);
}
};
So, what Im looking for is a few things:
1) am I going in the right direction with my observable?
2)how would I handle the subscription part of this?
3)any other advice related to replacing async tasks with RX because this is the first of several I need to do.
Edit:
This is where I have gotten and feel as if I am closer, but I still need guidance.etSearch is my EditText view
if(etSearch.length()>2){
Observable<String> o1 = Observable.just(etSearch.getText().toString());
o1.subscribeOn(Schedulers.io())
.observeOn(RxAndroidSchedulers.mainThread()).subscribe(new Action1<String>() {
@Override
public void call(String s) {
List<Member> MemberList =rest.getMemberList(s);
ListView ResultsListView = (ListView) findViewById(R.id.list);
MemberAdapter = new ResultRowAdapter(mContext, getLayoutInflater());
MemberAdapter.setMemberList(MemberList);
ResultsListView.setAdapter(MemberAdapter);
}
});}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…