Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. private static final String TAG = "MainActivity";
  4.  
  5. private ArrayAdapter adapter;
  6.  
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_main);
  11.  
  12. ListView list = (ListView) findViewById(R.id.theList);
  13. EditText theFilter = (EditText) findViewById(R.id.searchFilter);
  14.  
  15. Log.d(TAG, "onCreate: Started.");
  16.  
  17. ArrayList<String> names = new ArrayList<>();
  18. names.add("United States");
  19. names.add("Israel");
  20. names.add("England");
  21. names.add("France");
  22. names.add("Germany");
  23. names.add("Georgia");
  24.  
  25. adapter = new ArrayAdapter(this, R.layout.list_item_layout, names);
  26. list.setAdapter(adapter);
  27.  
  28. theFilter.addTextChangedListener(new TextWatcher() {
  29. @Override
  30. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  31.  
  32. }
  33.  
  34. @Override
  35. public void onTextChanged(CharSequence s, int start, int before, int count) {
  36.  
  37. (MainActivity.this).adapter.getFilter().filter(s);
  38.  
  39. }
  40.  
  41. @Override
  42. public void afterTextChanged(Editable s) {
  43.  
  44. }
  45. });
  46.  
  47. }
  48. }
  49.  
  50. public class MainActivity extends AppCompatActivity {
  51.  
  52. public static TextView data;
  53. public TextView dataNew;
  54.  
  55. Button b;
  56.  
  57. // Additional code for the search - Part 1
  58.  
  59. private static final String TAG = "MainActivity";
  60.  
  61. private ArrayAdapter adapter;
  62.  
  63. // Additional code for the search - Part 1
  64.  
  65. ListView listView;
  66. String[] fruitNames = {"USD", "ILS", "GBP", "CAD", "EUR"};
  67. String[] fruitDesc = {"United States", "Israel", "United Kingdom", "Canada", "Europe"};
  68. String[] currencyRates = {"1", "1", "1", "1", "1"};
  69. int[] fruitImages = {R.drawable.us5, R.drawable.il5, R.drawable.uk5, R.drawable.ca5, R.drawable.eu5};
  70.  
  71. @Override
  72. protected void onCreate(Bundle savedInstanceState) {
  73. super.onCreate(savedInstanceState);
  74. setContentView(R.layout.activity_main);
  75.  
  76. /// Additional code for the search - Part 2
  77.  
  78. Button b = (Button) findViewById(R.id.button);
  79. b.setOnClickListener( new View.OnClickListener() {
  80.  
  81. @Override
  82. public void onClick(View v) {
  83.  
  84. ListView list = (ListView) findViewById(R.id.listview);
  85. EditText theFilter = (EditText) findViewById(R.id.edittext);
  86.  
  87. Log.d(TAG, "onCreate: Started.");
  88.  
  89. adapter = new ArrayAdapter(MainActivity.this, R.layout.row_data, fruitNames);
  90. list.setAdapter(adapter);
  91.  
  92. theFilter.addTextChangedListener(new TextWatcher() {
  93. @Override
  94. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  95.  
  96. }
  97.  
  98. @Override
  99. public void onTextChanged(CharSequence s, int start, int before, int count) {
  100.  
  101. (MainActivity.this).adapter.getFilter().filter(s);
  102.  
  103. }
  104.  
  105. @Override
  106. public void afterTextChanged(Editable s) {
  107.  
  108. }
  109. });
  110.  
  111. }
  112. });
  113.  
  114. /// Additional code for the search - Part 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement