动态使用RX和MVVM模式将项目放入Spinner中?

我正在使用MVVM与Rxjava,这是我第一次使用Rxjava,我想通过Spinner中的响应填充项目。但我无法这样做。 spinner如何动态填充?动态使用RX和MVVM模式将项目放入Spinner中?

ApiInterface

@GET("client") 

Observable<List<ClientListApi>> clientListApi();

RegisterFragmentVm

public void getClientList() { 

ArrayList arrayList = new ArrayList();

ApiInterface apiInterface = setRetrofit();

apiInterface.clientListApi().subscribeOn(Schedulers.newThread())

.observeOn(AndroidSchedulers.mainThread())

.subscribe(new Observer<List<ClientListApi>>() {

@Override

public void onSubscribe(Disposable d) {

}

@Override

public void onNext(List<ClientListApi> clientListApis) {

int position = 0;

System.out.println("size of arraylist" + clientListApis.size());

for (int i = 0; i < position; i++) {

System.out.println("name" + clientListApis.get(position).getName());

}

}

@Override

public void onError(Throwable e) {

}

@Override

public void onComplete() {

}

});

// ArrayAdapter<String> sector_adapter = new ArrayAdapter<String>(mContext, R.layout.support_simple_spinner_dropdown_item, arrayList);

// sector_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

// fragmentRegisterBinding.spinner.setAdapter(sector_adapter);

}

RegisterFragment

@Nullable 

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

super.onCreateView(inflater, container, savedInstanceState);

fragmentRegisterBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_register, container, false);

registerFragmentVm = new RegisterFragmentVm(getContext(), fragmentRegisterBinding);

fragmentRegisterBinding.setRegisterVm(registerFragmentVm);

registerFragmentVm.getClientList();

return fragmentRegisterBinding.getRoot();

}

何这可以解决。我能够获得Response,但无法将其填充到Spinner中。

回答:

化妆接口

public interface SpinnerBankName { 

public void passBankName(List<ClientListApi> bankList);

}

VM

SpinnerBankName spinnerBankName; 

spinnerBankName = (SpinnerBankName) fragment;

@Overrid

public void onNext(List<ClientListApi> clientListApis) {

spinnerBankName.passBankName(clientListApis);

}

只是使界面以及要

类实现

以上是 动态使用RX和MVVM模式将项目放入Spinner中? 的全部内容, 来源链接: utcz.com/qa/260307.html

回到顶部