开发者

Android List Refresh

I'm working on refreshing a list in Android but can't seem to get it right.

I've used notifyDataSetChanged(); at every point that I thought applicable (currently using dialogs for input), but it doesn't work, and I've got to the point of plastering it around all over the place and it still won't开发者_运维百科 refresh.

Am I right in saying this should refresh the list while your looking at it, or it will rebuild the list and you still have to refresh the view?

If anyone has got any suggestions for the positioning of it in relation to constructing a list I'd be glad to hear.


Is this a ListActivity? I have a ListActivity in my project at the moment and I have my own adapter class within it that extends ArrayAdapter.

My experience is that calling notifyDataSetChanged() on my extended list adapter class instance does immediately cause a refresh of the list View being displayed. So, as soon as I call .notifyDataSetChanged() on my adapter instance, the list View is regenerated which therefore causes my adapter's implementation of getView() to be called to generate each individual row view again. So, the user selects a context menu item which triggers some change to the data and then a call to .notifyDataSetChanged(), and the screen instantly refreshes with the new data.

So to add some code snippets to be clear:

I have a ListActivity

public class VarListActivity extends ListActivity {

Within it, I extend ArrayAdapter

class VarAdapter extends ArrayAdapter{

...

    @Override
    public View getView(int position, View convertView, ViewGroup parent){

         // Creates the views based upon myData

    ...

    @Override
    public int getCount(){

    ...

And I create an instance of that array adapter

la = new VarAdapter(this, R.layout.row0);

And when a context menu item is selected

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.a_context_menu_option:

             // Does a call to perform modifications to myData

             la.notifyDataSetChanged();
         return true;

I'm just chucking this all down just in case it's of any similarity to your situation, but really we need to know a bit more about your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜