简体   繁体   中英

Recyclerview android studio “hiding”?

so I have a recyclerview, and in my recyclerview I have items. If I delete all the visible items in my recyclerview, one still appears to be left that was essentially "hiding" what is the cause of this? I believe that it is an easy fix but what is it?

public class AdapterTags extends  RecyclerView.Adapter<AdapterTags.ViewTags>{
private LayoutInflater mLayoutInflater;
private ArrayList<Search> ListSearch=new ArrayList<>();
public AdapterTags(Context context){
    mLayoutInflater=LayoutInflater.from(context);
}
public void setTagsList (ArrayList<Search> ListSearch){
    this.ListSearch=ListSearch;
    notifyItemRangeChanged(0,ListSearch.size());
}

@Override
public ViewTags onCreateViewHolder(ViewGroup parent, int viewType) {
    View view= mLayoutInflater.inflate(R.layout.fragment_tags, parent, false);
    ViewTags viewholder=new ViewTags(view);
    return viewholder;
}

@Override
public void onBindViewHolder(ViewTags holder, int position) {
    final Search currentTags=ListSearch.get(position);
    holder.mSearchText.setText(currentTags.getMtitle());
    holder.mAnswerPointsSearch.setText(currentTags.getMkey());
    holder.mSearchId.setText(currentTags.getMid());
    holder.mCourseId.setText(currentTags.getCourseId());
}

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

 class ViewTags extends RecyclerView.ViewHolder implements View.OnClickListener {
    private TextView mSearchText;
    private TextView mAnswerPointsSearch;
    private TextView mSearchId;
    private TextView mCourseId;



    public ViewTags(View itemView){
        super(itemView);
        mSearchText=(TextView)itemView.findViewById(R.id.SearchText);
        mAnswerPointsSearch=(TextView)itemView.findViewById(R.id.AnswerPointsSearch);
        mSearchId=(TextView)itemView.findViewById(R.id.SearchId);
        mCourseId=(TextView)itemView.findViewById(R.id.CourseTextView);
    }

calling activity

private void JsonRequestMethod() {
    mVolleySingleton = VolleySingleton.getInstance();
    mRequestQueue = mVolleySingleton.getRequestQueue();
    JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, URL_ANSWER, (String) null, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            ListSearch = parseJSONResponseQuestion(response);
            mAdapterDashBoard.setTagsList(ListSearch);
            System.out.println(response);
            System.out.println("it worked!!!");
        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            System.out.println(error);

        }
    });
    mRequestQueue.add(request);
}

I would recommend you to pass your items via constructor, and not to call notifyItemRangeChanged() as soon as you setItems. You should also check if your items is null in your getItemCount method, because if it is, your app is gonna crash. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM