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.
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.
Sir tell us how to make a medic alert app
ReplyDeleteOr study alert app
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/.
ReplyDeleteSir, PLEASE HELPP..
ReplyDeletehow to search in LISTVIEW that uses CUSTOMVIEW and the data comes from FIREBASE?
Alguien me peuda ayudar
ReplyDeletePlz say how to make a game in sketchware except word game
ReplyDeleteNice 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
ReplyDeleteHow to create AutoCompleteTextView in sketchware
ReplyDeleteError occur when I tried thesecodes
ReplyDeleteHow can I add it to linear1 instead of action bar!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHow can this be done in AndroidX, since the Android libraries are no longer available.
ReplyDeleteHi please help me on how to get spesific data from firebase please make a tutorialwill
ReplyDelete