回答編集履歴
3
コメント再現
test
CHANGED
@@ -40,8 +40,10 @@
|
|
40
40
|
public boolean onQueryTextChange(String text) {
|
41
41
|
Log.d("onQueryTextChange ***", "text="+text);
|
42
42
|
if(TextUtils.isEmpty(text)) {
|
43
|
+
//listView.clearTextFilter();
|
43
44
|
filter.filter(null);
|
44
45
|
} else {
|
46
|
+
//listView.setFilterText(text);
|
45
47
|
filter.filter(text);
|
46
48
|
}
|
47
49
|
return true;
|
2
修正
test
CHANGED
@@ -84,7 +84,7 @@
|
|
84
84
|
app:layout_constraintTop_toBottomOf="@id/searchView" />
|
85
85
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
86
86
|
```
|
87
|
-
実行時ログ
|
87
|
+
実行時ログ(SearchView に "2" を入力、"222" の行を選択)
|
88
88
|
```plain
|
89
89
|
D/onQueryTextChange ***: text=2
|
90
90
|
D/onItemClick ***: position=0
|
1
追記
test
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
onItemClick の position はフィルタリングされた表示上の位置ですが、同時に ListView#getItemAtPosition のパラメータもその範囲になりますのでそのまま指定出来ます。
|
1
|
+
行クリックで呼ばれる onItemClick の position はフィルタリングされた表示上の位置ですが、同時に ListView#getItemAtPosition のパラメータもその範囲になりますので、そのまま指定してデータを取り出すことが出来ます。
|
2
|
+
|
3
|
+
データの管理をどのオブジェクトがするのか/しているのかを決める/判断することは、オブジェクト指向としては大事なことです。
|
4
|
+
リストのデータはデータベースから読んでいますが、リストとして表示する為にそのデータを保持・管理しているのは Adapter ですし、 Adapter のデータを表示しているのは ListView です。
|
5
|
+
フィルタリングは ListView に指定しているのですから、 ListView も Adapter も飛び越えてデータベースから選択データを得るのでは無く、 ListView から得ることをまず考えられると良いと思います。
|
6
|
+
|
2
7
|
```java
|
3
8
|
import androidx.appcompat.app.AppCompatActivity;
|
4
9
|
import androidx.appcompat.widget.SearchView;
|