我有一个RecyclerView
。我想用 SearchView 让它可以过滤。我的应用程序基于Android Architecture Components
.
我创建了一个过滤方法searchView
。当我搜索某些内容时,它可以工作,但是当我清除其中的文本时searchView
,列表不会更改,并且仍然显示搜索数据。
活动:
private StudentAdapter mAdapter;
mAdapter = new StudentAdapter(this);
recyclerView.setAdapter(mAdapter);
//ViewModel
StudentViewModelFactory factory = new StudentViewModelFactory(mDb, mClassId);
StudentViewModel viewModel = ViewModelProviders.of(this, factory).get(StudentViewModel.class);
viewModel.getStudentEntries().observe(this, studentEntries -> mAdapter.setStudents(studentEntries));
//SearchView
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){
@Override
public boolean onQueryTextSubmit(String query){
return false;
}
@Override
public boolean onQueryTextChange(String newText){
mAdapter.getFilter().filter(newText);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
适配器:
public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.itemHolder> {
private List<StudentEntry> mStudentEntries;
private List<StudentEntry> filteredStudentEntries;
public StudentAdapter(Context context) {
this.context = context; …
Run Code Online (Sandbox Code Playgroud) android searchview android-recyclerview android-livedata android-viewmodel
我的应用程序中有一个导航视图,在应用程序样式中添加两行之后:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
Run Code Online (Sandbox Code Playgroud)
导航图标颜色更改为黑色,对于这个问题,我在样式中添加了以下行:
<item name="android:textColorSecondary">@android:color/white</item>
Run Code Online (Sandbox Code Playgroud)
现在导航图标又是白色的,但现在我有一个新问题。使用上面的代码,导航项的标题也改变了颜色。
我没有找到解决此干扰的方法
风格 :
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColorSecondary">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
导航菜单:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group
android:id="@+id/testGRP"
android:checkableBehavior="single"
>
<item android:title="???? : ?????? ????"
android:id="@+id/menuItem_StudentList11"
android:icon="@drawable/ic_arrow_drop_up"
/>
<item android:title="???? ????"
android:id="@+id/menuItem_StudentList_Quize1"
android:icon="@drawable/all_exam_icon"
/>
<item android:title="@string/Navigation_StudentList3"
android:id="@+id/menuItem_StudentList_Quize"
android:icon="@drawable/all_exam_icon"
/>
</group>
<item android:title="????????:"> //this line is title
<menu>
<item android:title="@string/Navigation_StudentList4"
android:id="@+id/menuItem_StudentList_MidTerm"
android:icon="@drawable/all_exam_icon"
/> …
Run Code Online (Sandbox Code Playgroud) android android-appcompat android-styles android-toolbar android-navigationview
我有一个sqlite数据库,我想将数据库更改为Room database
。
表之一没有任何主键,只有两个外键。
我使用以下查询在房间之前创建了表:
CREATE TABLE student_performance(
class_id int ,
student_id char(10),
class_date date ,
absent boolean DEFAULT 0,
delay boolean DEFAULT 0,
positive int DEFAULT 0,
negative int DEFAULT 0,
quiz float ,
FOREIGN KEY (student_id , class_id) REFERENCES student(student_id , class_id)
ON DELETE CASCADE
ON UPDATE CASCADE);
Run Code Online (Sandbox Code Playgroud)
现在我为房间定义表:
@Entity(tableName = "performance",
foreignKeys = {@ForeignKey(
entity = StudentEntry.class,
parentColumns = {CLASS_ID, STUDENT_ID},
childColumns = {CLASS_ID, STUDENT_ID},
onDelete = CASCADE, onUpdate = CASCADE)})
public class PerformanceEntry {
. …
Run Code Online (Sandbox Code Playgroud)