带有BottomNavigationView的RecyclerView在显示项目时不会显示更改

时间:2019-02-21 15:47:23

标签: android dependency-injection android-recyclerview bottomnavigationview

当我尝试重构应用程序并使用依赖注入时,“ RecyclerView”和“ BottomNavigationView”出现问题。问题是当我单击导航视图中的项目时,“ RecyclerView”不会更改列表中的项目。我的HTTP请求具有代码状态,并基于该请求获取商品。我检查了API并正常工作,在“ LOGCAT”中也得到了200代码。这是零件的代码。当活动打开的应用程序将显示状态代码为0的数据时,然后当我们将状态代码更改为底部时,什么也不会改变,但我仍然得到相同的列表。

这不是重复的,因为我正在使用依赖关系注入和MVP,并且我还添加了依赖关系注入标记,因为当我使用依赖关系注入并且是初学者时,这种情况正在发生。

活动:我在onCreate中调用方法以获取数据,并查看以下数据。

private void setupData() {
    bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            if (item.getItemId() == R.id.new_request) {
                mPresenter.setupLoadOrders("0");
            } else if (item.getItemId() == R.id.canceled_request) {
                mPresenter.setupLoadOrders("-1");
            } else if (item.getItemId() == R.id.submited_request) {
                mPresenter.setupLoadOrders("1");
            } else if (item.getItemId() == R.id.added_request) {
                mPresenter.setupLoadOrders("2");
            }
            return true;
        }
    });

    mPresenter.setupLoadOrders("0");
}

private void setupView() {

    recyclerRequests.setLayoutManager(new LinearLayoutManager(this));
    recyclerRequests.setHasFixedSize(true);
}
@Override

public void displayOrders(List<Requests> requests) {
    requestAdapter.setData(requests);
    recyclerRequests.setAdapter(requestAdapter);
}

和演示者:

@Override
public void setupLoadOrders(String statusReq) {

        compositeDisposable.add(atlasApiReference.getRequest(Common.currentUser.getPhone(), statusReq)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<List<Requests>>() {
                    @Override
                    public void accept(List<Requests> requests) throws Exception {
                        mView.displayOrders(requests);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        Log.e("Log",throwable.getMessage());
                    }
                }));
}

public void unSubscribe()
{
    AtlasRxJavaUtil.unsubscribeClear(compositeDisposable);
}

和适配器:

private List<Requests> requestsList;

@Inject
public RequestAdapter() {
    requestsList = new ArrayList<>();
}

@NonNull
@Override
public RequestAdapterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    return new RequestAdapterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.request_detail_layout, parent, false));

}

@Override
public void onBindViewHolder(@NonNull RequestAdapterViewHolder holder, final int position) {
    holder.request_number.setText(new StringBuilder(" ").append(requestsList.get(position).getId()));
    holder.request_name.setText(new StringBuilder(" ").append(requestsList.get(position).getNameReq()));


}


public class RequestAdapterViewHolder extends RecyclerView.ViewHolder {



    public PsTextView request_number,request_name;
    CardView request_detail_layout;

        public RequestAdapterViewHolder(final View itemView) {
            super(itemView);

            request_number = (PsTextView)itemView.findViewById(R.id.request_number);
            request_name = (PsTextView)itemView.findViewById(R.id.request_name);
            request_detail_layout = (CardView)itemView.findViewById(R.id.request_detail_layout);

            request_detail_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    Common.currentRequest = requestsList.get(getAdapterPosition());
                    itemView.getContext().startActivity(new Intent(itemView.getContext(), ShowDetail.class));
                }
            });

        }

}

@Override
public int getItemCount() {
    return requestsList.size();
}


public void setData(List<Requests> requestsList){

        this.requestsList.addAll(requestsList);
        notifyDataSetChanged();

}

1 个答案:

答案 0 :(得分:0)

尝试删除以下行:

public class ArrayStack<Type> implements Stack<Type> {

private int maxSize;
private int top;
private Type [] nodes;

@SuppressWarnings("unchecked")

public ArrayStack(int n){
    maxSize = n ;
    top = -1 ;
    nodes = (Type[]) new Object[n];
}



@SuppressWarnings("unchecked")

public Stack<Type> copy() {

    int n = nodes.length;
    Type[] ns = (Type[]) new Object[n];

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

        ns[i]= nodes[i];
    }



    return ns;
}

有关此post的更多信息。