2011-10-21 49 views
2

它是TabActivity调用的活动。ANDROID:在收到通知时,我想用新数据刷新listView

我想:如果我收到新的通知,我想刷新当前活动的列表。

public class TestListActivity extends ListActivity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    ListView lv = null; 
    super.onCreate(savedInstanceState); 

    setListAdapter(new ArrayAdapter<String>(this, R.layout.test_list, ListUtil.asStringList(TestServiceUtil.getTests()))); 

    lv = getListView(); 
    lv.setSelector(R.drawable.listindicator); 
    lv.setTextFilterEnabled(true); 
    lv.setOnItemClickListener(new OnItemClickListener() { 

     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      Intent intent = new Intent(TestListActivity.this, TestViewActivity.class); 

      // Next create the bundle and initialize it 
      Bundle bundle = new Bundle(); 

      // Add the parameters to bundle as 
      bundle.putLong("testId", TestServiceUtil.getTests().get(position).getTestId()); 

      // Add this bundle to the intent 
      intent.putExtras(bundle); 

      // Start next activity 
      TestListActivity.this.startActivity(intent); 
     } 
    }); 
} 
} 

我只需要例子,我可以如何刷新列表。

+0

什么样的通知? – fredley

回答

1

我推荐在ArrayAdapter上使用notifyDataSetChanged()。

+0

是的,谢谢我已经使用它,它的工作原理;) – nayden