Put Item in the Spinner dynamically using RX with MVVM pattern?

26 views
0

i am using MVVM with Rxjava ,this is the first time i am using Rxjava, i want to populate the item through the response in the Spinner.But i am not able to do so.How can spinner be populated dynamically?

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();

}

How can this be solved. I am able to get Response but not able to populate it in Spinner.