Kotlin SQLite example - Search with Listview | Android
Kotlin
104
sqlite
5
listview
6
android
87
Male avatar

loveprogramming viết ngày 14/04/2021

https://grokonez.com/android/kotlin-sqlite-example-search-with-listview-android

In previous post, we had known how to make CRUD operations with Android ListView. In this tutorial, we're gonna look at how to implement Search function with SearchView.

Related posts:

I. Technologies

  • Android Studio 3
  • Kotlin 1.1.51

    II. Overview

    1. Goal

    We have had an Android App that supports showing, inserting, editing, deleting Notes from/to SQLite Database with ListView:

kotlin-sqlite-goal

In this tutorial, we will add Search function for this app:

kotlin-sqlite-search-goal

2. Search function

2.1 SearchView

SearchView widget is available from Android 3.0. It is recommended to insert the search widget as an action view in the app bar.

For example, enable the widget during the onCreateOptionsMenu() callback:


override fun onCreateOptionsMenu(menu: Menu?): Boolean {
    menuInflater.inflate(R.menu.menu_main, menu)

    val searchView: SearchView = menu!!.findItem(R.id.searchNote).actionView as SearchView
    val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager

    searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName))
    searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {

        override fun onQueryTextSubmit(query: String): Boolean {
            loadQuery("%" + query + "%")
            return false
        }

        override fun onQueryTextChange(newText: String): Boolean {
            return false
        }
    })

We need to enable assisted search for each SearchView by calling setSearchableInfo() and passing it the SearchableInfo object that represents searchable configuration.

More at:

Kotlin SQLite example - Search with Listview | Android

https://grokonez.com/android/kotlin-sqlite-example-search-with-listview-android

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

545 bài viết.
97 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 9 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 7 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 7 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/kotlin/kotlinreadwritecsvfileexample How to read/write CSV file in Kotlin In this tutorial, we're gonna look at examples tha...
loveprogramming viết 3 tháng trước
0 0
Male avatar
0 0
https://grokonez.com/frontend/angular/angular6/kotlinspringbootangular6crudhttpclientmysqlexamplespringdatajparestapisexample Kotlin Spring Boot +...
loveprogramming viết 4 tháng trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
545 bài viết.
97 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!