Advertisement
Guest User

Untitled

a guest
May 6th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. String[]fruits = {"apple", "avocado", "banana", "blackberry", "blueberry", "coconut", "durian", "mango", "melon"};
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_main);
  7.  
  8. ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, fruits);
  9.  
  10. AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autocom);
  11. autoCompleteTextView.setAdapter(stringArrayAdapter);
  12. autoCompleteTextView.setTextColor(Color.RED);
  13.  
  14. ListView lv = (ListView) findViewById(R.id.lv);
  15. lv.setAdapter(stringArrayAdapter);
  16.  
  17. }
  18.  
  19. <?xml version="1.0" encoding="utf-8"?>
  20. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  21. xmlns:tools="http://schemas.android.com/tools"
  22. android:layout_width="match_parent"
  23. android:layout_height="match_parent"
  24. android:paddingBottom="@dimen/activity_vertical_margin"
  25. android:paddingLeft="@dimen/activity_horizontal_margin"
  26. android:paddingRight="@dimen/activity_horizontal_margin"
  27. android:paddingTop="@dimen/activity_vertical_margin"
  28. tools:context="com.example.android.autocompletenativesample.MainActivity">
  29.  
  30. <TextView
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"
  33. android:layout_alignParentLeft="true"
  34. android:layout_alignParentTop="true"
  35. android:layout_marginTop="15dp"
  36. android:text="Pick a Fruit"
  37. android:id="@+id/tv"
  38. />
  39. <AutoCompleteTextView
  40. android:layout_width="match_parent"
  41. android:layout_height="wrap_content"
  42. android:layout_alignParentLeft="true"
  43. android:id="@+id/autocom"
  44. android:layout_below="@+id/tv"
  45. android:layout_marginLeft="36dp"
  46. android:layout_marginTop="17dp"
  47. android:completionThreshold="1"
  48. />
  49. <TextView
  50. android:layout_width="wrap_content"
  51. android:layout_height="wrap_content"
  52. android:text="ListView Implementation"
  53. android:layout_below="@+id/autocom"
  54. android:id="@+id/tv2"
  55. />
  56. <ListView
  57. android:layout_width="match_parent"
  58. android:layout_height="wrap_content"
  59. android:id="@+id/lv"
  60. android:layout_below="@+id/tv2"
  61. >
  62.  
  63. </ListView>
  64.  
  65. <TextView
  66. android:layout_width="wrap_content"
  67. android:layout_height="wrap_content"
  68. android:text="RecyclerView Implementation"
  69. android:layout_below="@+id/lv"
  70. />
  71. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement