SearchView for String list in Sketchware

To implement a SearchView for a simple ListView showing a String list in Sketchware, follow the steps given below.

1. Create a new project in Sketchware.

2. In VIEW area add a ListView listview1.

3. Switch On AppCompat and Design.

4. Create a String List list.

5. Create a more block extra.

6. In the more block extra, use an add source directly block and put codes to declare a SearchView searchview and an ArrayAdapter adapter. After that add the SearchView as an OptionsMenu item.
}
android.support.v7.widget.SearchView searchview;
ArrayAdapter<String> adapter;
@Override
public boolean onCreateOptionsMenu( Menu menu) {
menu.add(0,0,0,"search").setActionView(searchview).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
{

7. In onCreate event, add items to the String List list.
8. After adding items to the list use add source directly blocks and put following codes:
i. Define the ArrayAdapter and set it as adapter of ListView.
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
listview1.setAdapter(adapter);

ii. Define SearchView and add it to Toolbar.
searchview = new android.support.v7.widget.SearchView(this);

iii. Set OnQueryTextListener for the SearchView.
searchview.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener(){
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
String text = newText;
adapter.getFilter().filter(text);
return false;
}
});

9. Save and run the project. You will see the search icon on the Toolbar. You can click on it and search the ListView.






Comments

  1. Sir tell us how to make a medic alert app
    Or study alert app

    ReplyDelete
  2. A person speak Within the much more prevent additional, make use of a good include supply straight prevent as well as place rules in order to announce the Search View search view as well as a good Array Adapter adapter. Next include the actual Search View being an Options Menu product. You may check it at http://www.ukraineoutsourcingrates.com/javascript-development-ukraine-rates/.

    ReplyDelete
  3. Sir, PLEASE HELPP..
    how to search in LISTVIEW that uses CUSTOMVIEW and the data comes from FIREBASE?

    ReplyDelete
  4. Plz say how to make a game in sketchware except word game

    ReplyDelete
  5. Nice search view but how can I add a search view for a music player app ..I tried all but to no avail instead it showed search view adapted for string

    ReplyDelete
  6. How to create AutoCompleteTextView in sketchware

    ReplyDelete
  7. Error occur when I tried thesecodes

    ReplyDelete
  8. How can I add it to linear1 instead of action bar!

    ReplyDelete

Post a Comment

Popular posts from this blog

A Flash Light App in Sketchware

Create Music Player app in Sketchware

Simple car racing android game in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Firebase auth in Sketchware for Login Activity