lundi 25 mai 2015

Problems calling notifyDataSetChanged

I am having trouble getting data to display correctly in my recyclerview. The data is retrieved from the server using ion and is entered into a sqlite database. The recyclerview displays whatever was previously called and entered into the database, and not what is currently being called and entered into the database. I am reasonable sure that onCompleted executes on the main thread, so I am not sure exactly where my problem is.

Im not sure if this is relevent, but my adapter just extends this http://ift.tt/1vgEJyq

My fragment

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
    DbHelper dbHelper = new DbHelper(getActivity());

    //Calls ion in another method
    getData();
    View view = inflater.inflate(R.layout.fragment_thread, container, false);

    recyclerView = (RecyclerView) view.findViewById(R.id.List);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    myAdapter = new myAdapter(dbHelper.getCursor());

    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(myAdapter);
    return view;
}

The ion request is pretty standard

    Ion.with(context)
            .load(JsonUrl)
            .asJsonObject()
            .setCallback(new FutureCallback<JsonObject>() {

                @Override
                public void onCompleted(Exception e, JsonObject jsonObject) {

                    /*
                    Parses json and enters it into the database.
                     */

                    myAdapter.notifyDataSetChanged()
                }
            }

Aucun commentaire:

Enregistrer un commentaire