I have two custom dynamic list views, one in a navigation view and one in the main layout like so
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/jobs">
</ListView>
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/nav_view">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Subjects"
android:choiceMode="singleChoice"
android:listSelector="#ADADAD"
>
</ListView>
</LinearLayout>
</android.support.design.widget.NavigationView>
I'm using View Model's observe function to fill both the lists, something like this. Both the lists are filled using the same database
activityViewModel.getAllGroups().observe(this, new Observer<List<String>>() {
@Override
public void onChanged(@Nullable List<String> strings) {
Groups = strings;
navDrawListAdapter.setGroups(strings);
}
});
activityViewModel.getAllActivites().observe(this, new Observer<List<Activity>>() {
@Override
public void onChanged(@Nullable List<Activity> activities) {
mactivities = activities;
tasksListAdapter.setmTasks(activities);
}
});
Now whenever someone clicks on the list in the navigation drawer I want to the other list to show only the relevant items corresponding to the selected row.
e.g. if "Trains" is selected in the navigation drawer I want to only show to items where attribute 'type' is "Trains"
I've tried to set the onClickListener for the navigation list adapter and tried to update the data on the other adapter but that made the list change every click and if I clicked on some other navigation element it made the list empty
void setmTasks(List<Activity> activities,String Typename){
mTasks = activities;
for(int i=0;i<activities.size();i++)
if(!activities.get(i).getType().equals(Typename))
mTasks.remove(activities.get(i));
notifyDataSetChanged();
}
How do I go about this
Thanks in Advance