Guest User

Untitled

a guest
Apr 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. package com.example.android.miwok;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.widget.ArrayAdapter;
  6. import android.widget.ListView;
  7. import java.util.ArrayList;
  8.  
  9.  
  10. public class NumbersActivity extends AppCompatActivity {
  11.  
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.acitivity_numbers);
  16.  
  17. //Create an arrayList of words
  18. ArrayList<String> words = new ArrayList<>();
  19. words.add("one");
  20. words.add("two");
  21. words.add("three");
  22. words.add("four");
  23. words.add("five");
  24. words.add("six");
  25. words.add("seven");
  26. words.add("eight");
  27. words.add("nine");
  28. words.add("ten");
  29.  
  30. // Create an {@link ArrayAdapter}, whose data source is a list of Strings. The
  31. // adapter knows how to create layouts for each item in the list, using the
  32. // simple_list_item_1.xml layout resource defined in the Android framework.
  33. // This list item layout contains a single {@link TextView}, which the adapter will set to
  34. // display a single word.
  35. ArrayAdapter<String> itemsAdapter =
  36. new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, words);
  37.  
  38. // Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
  39. // There should be a {@link ListView} with the view ID called list, which is declared in the
  40. // activity_numbers.xml layout file.
  41. ListView listView = (ListView) findViewById(R.id.list);
  42.  
  43. // Make the {@link ListView} use the {@link ArrayAdapter} we created above, so that the
  44. // {@link ListView} will display list items for each word in the list of words.
  45. // Do this by calling the setAdapter method on the {@link ListView} object and pass in
  46. // 1 argument, which is the {@link ArrayAdapter} with the variable name itemsAdapter.
  47. if (listView != null){
  48. listView.setAdapter(itemsAdapter);
  49.  
  50. }
  51.  
  52.  
  53. }}
Add Comment
Please, Sign In to add comment