Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- private static final String TAG = "MainActivity";
- private ArrayAdapter adapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ListView list = (ListView) findViewById(R.id.theList);
- EditText theFilter = (EditText) findViewById(R.id.searchFilter);
- Log.d(TAG, "onCreate: Started.");
- ArrayList<String> names = new ArrayList<>();
- names.add("United States");
- names.add("Israel");
- names.add("England");
- names.add("France");
- names.add("Germany");
- names.add("Georgia");
- adapter = new ArrayAdapter(this, R.layout.list_item_layout, names);
- list.setAdapter(adapter);
- theFilter.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- (MainActivity.this).adapter.getFilter().filter(s);
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- });
- }
- }
- public class MainActivity extends AppCompatActivity {
- public static TextView data;
- public TextView dataNew;
- Button b;
- // Additional code for the search - Part 1
- private static final String TAG = "MainActivity";
- private ArrayAdapter adapter;
- // Additional code for the search - Part 1
- ListView listView;
- String[] fruitNames = {"USD", "ILS", "GBP", "CAD", "EUR"};
- String[] fruitDesc = {"United States", "Israel", "United Kingdom", "Canada", "Europe"};
- String[] currencyRates = {"1", "1", "1", "1", "1"};
- int[] fruitImages = {R.drawable.us5, R.drawable.il5, R.drawable.uk5, R.drawable.ca5, R.drawable.eu5};
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- /// Additional code for the search - Part 2
- Button b = (Button) findViewById(R.id.button);
- b.setOnClickListener( new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ListView list = (ListView) findViewById(R.id.listview);
- EditText theFilter = (EditText) findViewById(R.id.edittext);
- Log.d(TAG, "onCreate: Started.");
- adapter = new ArrayAdapter(MainActivity.this, R.layout.row_data, fruitNames);
- list.setAdapter(adapter);
- theFilter.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- (MainActivity.this).adapter.getFilter().filter(s);
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- });
- }
- });
- /// Additional code for the search - Part 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement