0

I am facing a problem with regards to the grid view update.. My Grid View will contain all the words found by the user.. The records will only be shown when you exit the app.. When I open my app, it contains the updated list view... What should I do here... I am looking for the possibility of using the notifyDataSetChanged() , but I don't know how to do it and where to put it... Anyone knows about this?

Here is my code of showing data in gridview..

//sliding menu onChange
@Override
public void onContentChanged()
{
    super.onContentChanged();
    mOpenButton = (Button) findViewById( R.id.button_open );
    mDrawer = (MultiDirectionSlidingDrawer) findViewById( R.id.drawer);
    GridView gridview = (GridView) findViewById(R.id.gridView1);
    WordGuessedHandler guessed = new WordGuessedHandler(this);
    List <WordGuessed> guessedList = guessed.getAllWordGuessed();
    List<String> wordsList = new ArrayList<String>();
    for(WordGuessed wg:guessedList){
        wordsList.add(wg.getWord());
    }
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, wordsList);
    gridview.setAdapter(adapter);
}
dakshbhatt21
  • 3,558
  • 3
  • 31
  • 40
edmund02
  • 55
  • 8
  • call `adapter.notifyDataSetChanged()` to update your listview. – Raghunandan Jul 25 '13 at 14:22
  • Wait.. I'll try it.. I'll comment shortly after I tested it.. BTW thanks for the reply – edmund02 Jul 25 '13 at 14:28
  • Still, the list view does not update its content.. – edmund02 Jul 25 '13 at 14:32
  • Please... I'm stucked in here.. Help me.. I need this to proceed to the other one... – edmund02 Jul 25 '13 at 14:47
  • `adapter.notifyDataSetChanged()` will work if the underlying data to your listview changes call this method. It will work. But i don't understand your requirement correctly. – Raghunandan Jul 25 '13 at 14:48
  • Okay.. to make it clear.. I am using a sliding menu and this displays the word already guessed by the user... What my requirement is, I need to show them in a gridView... I have done the saving of the words and now I am having a problem with its retrieval.. It should update once the data is saved.. – edmund02 Jul 25 '13 at 14:58

1 Answers1

0

First tell the adapter to notify that the data has changed and then set the adapter again.

adapter.notifyDataChanged();
grid.setAdapter(adapter);
XorOrNor
  • 8,868
  • 12
  • 48
  • 81