سؤال

I am using a ListFragment and display a dynamic list from a database, I want to update the view and change the order of the list by running the ASYNCTASK again. At them moment when this is done the new data just gets put on the bottom of the current list.

asynctask in fragment:

creates the list adapter and displays it

        protected void onPostExecute(String file_url) {
        // // dismiss the dialog once done
        pDialog.dismiss();

        fragment_module.this.getListView().invalidateViews(); //does nothing
         adapter = new SimpleAdapter(getActivity(),
                questionsList, R.layout.questionlistitem, new String[] {
                        TAG_QUESTIONVOTE, TAG_QUESTIONTEXT,
                        TAG_QUESTIONANSWER, CONCATINATED_SUBMISSION,
                        TAG_QUESTIONID }, new int[] { R.id.upvoteText,
                        R.id.questionText, R.id.questionAnswer,
                        R.id.submission, R.id.qid });
        // updating listview

        setListAdapter(adapter);

    }

The view is to change after an onclick event is just want the list to be cleared so it can update.

update Code called to update view and re-run asynctask

                      fragment_module.this.getListView().invalidateViews();
                  getQuestionList obj2 = new getQuestionList();
                    obj2.execute();
هل كانت مفيدة؟

المحلول

you can use something like

collection.clear();
listview.getAdapter().notifyDataSetChanged();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top