Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. 'public class MainActivity extends ActionBarActivity {
  2.  
  3. ArrayList<String> list;
  4. ListView listview;
  5. ArrayAdapter<String> listAdapter;
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.activity_main);
  10.  
  11.  
  12.  
  13. listview = (ListView) findViewById(R.id.listView);
  14.  
  15. list = new ArrayList<String>();
  16.  
  17.  
  18. list.add("1");
  19. listAdapter();
  20. try {
  21. Thread.sleep(3000);
  22. } catch (InterruptedException e) {
  23. // TODO Auto-generated catch block
  24. e.printStackTrace();
  25. }
  26.  
  27.  
  28. list.add("2");
  29. listAdapter.setNotifyOnChange(true);
  30.  
  31. listAdapter();
  32. try {
  33. Thread.sleep(3000);
  34. } catch (InterruptedException e) {
  35. // TODO Auto-generated catch block
  36. e.printStackTrace();
  37. }
  38. list.add("3");
  39. listAdapter.setNotifyOnChange(true);
  40.  
  41. listAdapter();
  42. try {
  43. Thread.sleep(3000);
  44. } catch (InterruptedException e) {
  45. // TODO Auto-generated catch block
  46. e.printStackTrace();
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. }
  57.  
  58.  
  59. private void listAdapter() {
  60.  
  61. listview.invalidateViews();
  62. listAdapter = new ArrayAdapter<String>(this,
  63. R.layout.listadapter, list);
  64. // put adapter in list view
  65. listview.setAdapter(listAdapter);
  66. listAdapter.setNotifyOnChange(true);
  67. }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement