Android 阵列适配器没有';t更新

Android 阵列适配器没有';t更新,android,android-arrayadapter,rx-java,retrofit2,Android,Android Arrayadapter,Rx Java,Retrofit2,我有一个ArrayAdapter: public class PlacesAutoCompleteAdapter extends ArrayAdapter<String> implements Filterable{ List<String> resultList; private OnAutoCompleteListener listener; private Context mContext; private int mResource; public Pl

我有一个ArrayAdapter:

public class PlacesAutoCompleteAdapter extends ArrayAdapter<String>  implements Filterable{

List<String> resultList;
private OnAutoCompleteListener listener;

private Context mContext;
private int mResource;


public PlacesAutoCompleteAdapter(Context context, int resource,List<String>resultList, OnAutoCompleteListener listener) {
    super(context, resource);

    mContext = context;
    mResource = resource;
    this.resultList = resultList;
    this.listener = listener;
}

@Override
public int getCount() {
    // Last item will be the footer
    return resultList.size();
}
public void updateList(List<String>values ){
    this.resultList = values;
    notifyDataSetChanged();
}

@Override
public String getItem(int position) {
    return resultList.get(position);
}

@Override
public Filter getFilter() {
    Filter filter = new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults filterResults = new FilterResults();
            if (constraint != null) {
                List<String> resultList = listener.onAutoComplete(constraint.toString());

                Log.d(getClass().getName(),String.valueOf(resultList.size()));
                filterResults.values = resultList;
                filterResults.count = resultList.size();
            }

            return filterResults;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            if (results != null && results.count > 0) {
                notifyDataSetChanged();
            }
            else {
                notifyDataSetInvalidated();
            }
        }
    };

    return filter;
}
}
公共类PlacesAutoCompleteAdapter扩展ArrayAdapter实现可过滤{
列表结果列表;
专用OnAutoCompleteListener侦听器;
私有上下文;
私人国际资源;
public PlacesAutoCompleteAdapter(上下文上下文、int资源、ListresultList、OnAutoCompleteListener侦听器){
超级(上下文、资源);
mContext=上下文;
mResource=资源;
this.resultList=resultList;
this.listener=listener;
}
@凌驾
public int getCount(){
//最后一项是页脚
返回resultList.size();
}
公共无效更新列表(Listvalues){
this.resultList=值;
notifyDataSetChanged();
}
@凌驾
公共字符串getItem(int位置){
返回resultList.get(位置);
}
@凌驾
公共过滤器getFilter(){
过滤器过滤器=新过滤器(){
@凌驾
受保护的筛选器结果性能筛选(CharSequence约束){
FilterResults FilterResults=新的FilterResults();
if(约束!=null){
List resultList=listener.onAutoComplete(constraint.toString());
Log.d(getClass().getName(),String.valueOf(resultList.size());
filterResults.values=结果列表;
filterResults.count=resultList.size();
}
返回过滤器结果;
}
@凌驾
受保护的void publishResults(CharSequence约束、FilterResults结果){
if(results!=null&&results.count>0){
notifyDataSetChanged();
}
否则{
notifyDataSetionValidated();
}
}
};
回流过滤器;
}
}
由此可流动性得出的结果:

    void addToList(Places places){
    places.getPredictions().stream().forEach(s->System.out.println(s.getDescription()));

    places.getPredictions()
            .stream()
            .map(s->resultList.add(s.getDescription()));
}

@Override
public List<String> loadPlaces(String input) {

    HappyParkApp.getInstance().createAppComponent().inject(this);

    PlaceAPIService service = retrofit.create(PlaceAPIService.class);

    Flowable<Places> places = service.getPlaces(Constants.APIKEY,Constants.TYPES,Constants.LANGUAGE,Constants.COMPONENTS,input);

    places.subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(newPlace -> addToList(newPlace));

    return resultList;
}
}
void addToList(位置){
places.getPredictions().stream().forEach(s->System.out.println(s.getDescription());
places.getPredictions()
.stream()
.map->resultList.add(s.getDescription());
}
@凌驾
公共列表加载位置(字符串输入){
HappyParkApp.getInstance().createAppComponent().inject(此);
PlaceAPIService=reformation.create(PlaceAPIService.class);
可流动位置=service.getPlaces(Constants.APIKEY、Constants.TYPES、Constants.LANGUAGE、Constants.COMPONENTS、input);
places.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.订阅(newPlace->addToList(newPlace));
返回结果列表;
}
}
这就是服务:

public interface PlaceAPIService {

@GET("json")
Flowable<Places> getPlaces(@Query("key")String API,
                             @Query("types")String address,
                             @Query("language")String language,
                             @Query("components")String component,
                             @Query("input") String input);
公共接口服务{
@获取(“json”)
可流动的getPlaces(@Query(“key”)字符串API,
@查询(“类型”)字符串地址,
@查询(“语言”)字符串语言,
@查询(“组件”)字符串组件,
@查询(“输入”)字符串输入);
}

这是正确的,我可以看到一个日志,以了解服务是否良好。 问题是显示适配器中项目的日志始终为0。 为什么? 在哪里可以更新适配器

谢谢

编辑:这是模型、视图和演示者:

public class APIModel implements AddWithText.Model {

@Inject
Retrofit retrofit;

AddWithText.Presenter presenter;

public APIModel(AddWithText.Presenter presenter) {
    this.presenter = presenter;
}

final List<String> resultList = new ArrayList<>();

void addToList(Places places){
    places.getPredictions().stream().forEach(s->System.out.println(s.getDescription()));

    places.getPredictions()
            .stream()
            .map(s->resultList.add(s.getDescription()));
}

@Override
public List<String> loadPlaces(String input) {

    HappyParkApp.getInstance().createAppComponent().inject(this);

    PlaceAPIService service = retrofit.create(PlaceAPIService.class);

    Flowable<Places> places = service.getPlaces(Constants.APIKEY,Constants.TYPES,Constants.LANGUAGE,Constants.COMPONENTS,input);

    places.subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(newPlace -> addToList(newPlace));

    return resultList;
}
公共类APIModel实现AddWithText.Model{
@注入
改造;
AddWithText.Presenter Presenter;
公共APIModel(AddWithText.Presenter Presenter){
this.presenter=演示者;
}
最终列表结果列表=新的ArrayList();
无效地址列表(位置){
places.getPredictions().stream().forEach(s->System.out.println(s.getDescription());
places.getPredictions()
.stream()
.map->resultList.add(s.getDescription());
}
@凌驾
公共列表加载位置(字符串输入){
HappyParkApp.getInstance().createAppComponent().inject(此);
PlaceAPIService=reformation.create(PlaceAPIService.class);
可流动位置=service.getPlaces(Constants.APIKEY、Constants.TYPES、Constants.LANGUAGE、Constants.COMPONENTS、input);
places.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.订阅(newPlace->addToList(newPlace));
返回结果列表;
}
}

创建视图时的公共视图(布局、充气机、视图组容器、捆绑包保存状态) { //为该碎片膨胀布局 视图根视图=充气器。充气(R.layout.fragment\u添加\u文本,容器,false); ButterKnife.bind(这个,rootView); HappyParkApp.getInstance().createAppComponent().inject(此); presenter=新的AddWithTextPresenter(); adapter=新位置自动完成适配器(getActivity(),R.layout.list\u项,自动完成,此); DatabaseReference root=FirebaseDatabase.getInstance().getReference(); 最终数据库引用条件=root.child(“条件”); insertText.setAdapter(适配器); 返回rootView; } @凌驾 恢复时公开作废(){ super.onResume(); presenter.setView(此文件); } @凌驾 自动完成的公共列表(字符串){ 列表结果=presenter.onTextChanged(字符); 返回结果; } @凌驾 公共无效刷新列表(列表结果列表){ adapter.updateList(结果列表); } 公共类AddWithTextPresenter实现AddWithText.Presenter{ AddWithText.View; AddWithText.Model; @注入 public AddWithTextPresenter(){ 模型=新的APIModel(本); } @凌驾 未完成的公共void(列表结果列表){ 查看刷新列表(结果列表); } @凌驾 public void setView(AddWithText.View视图){ this.view=视图; } @凌驾 公共列表onTextChanged(字符串){ 返回模型。装载位置(字符); }
}你在这里做错了

adapter = new PlacesAutoCompleteAdapter(getActivity(),R.layout.list_item,autoComplete,this);
在适配器中,您有4个参数,并且只传递3个

第二步检查您在这里获取的数据-

@Override
public List<String> onAutoComplete(String character) {
    List<String> result = presenter.onTextChanged(character);
    return result;
}
@覆盖
自动完成的公共列表(字符串){
列表结果=presenter.onTextChanged(字符);
返回结果;
}
如果是这样的话,那么您就不会在任何地方向适配器传递数据。添加方法l
@Override
public List<String> onAutoComplete(String character) {
    List<String> result = presenter.onTextChanged(character);
    return result;
}
public List<String> getData() {
    return resultList;
}

public void setData(List<String> mData) {
    this.resultList = mData;
}

public void addItems(List<String> mData) {

    if (this.resultList != null) {
        this.resultList.addAll(mData);
        notifyItemInserted(this.resultList.size());
    }
}