1

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

Milind Mevada
  • 3,145
  • 1
  • 14
  • 22
masked_man
  • 11
  • 2
  • Does the navigation list contain different attributes? If yes then can one or more be true for the same item? If yes then you'd be better off providing the user checks instead. If however the list is mutually exclusive or otherwise can be represented as a list, then depending on the architecture of your app you may use either callbacks/interfaces (recommended) or local broadcasts. These will allow you to notify the main `ListView` while giving you a mechanism to pass the attribute. Using this attribute you can populate the main `ListView`. – Abbas Aug 24 '18 at 12:02
  • @Abbas How do I implement the interface? I've tried sending a string along with the objects to the main list adapter to only add the relevant data to the list but it doesn't work. – masked_man Aug 24 '18 at 13:42

1 Answers1

0

https://github.com/rey5137/material this ref may help you DrawerAdapter in slideing menu element click goes to selected viewpage

@Override
        public void onPageSelected(int position) {
            mDrawerAdapter.setSelected(mItems[position]);
            mSnackBar.dismiss();
        }

in mainactivity