SearchView with multiple fragments using viewpager in android

前端 未结 3 1750
死守一世寂寞
死守一世寂寞 2021-02-02 16:06

I want to implement SearchView with multiple fragments present in a viewPager. All fragemnts contains lists and I want to filter those lists and create a new ListView which has

3条回答
  •  [愿得一人]
    2021-02-02 16:34

    Below hint may help you

    public class AnyActivity extends AppCompatActivity { private ListenFromActivity activityListener1; }

    then define interface with separate file

    public interface ListenFromActivity { void doSearchInFragment(String SearchKey); }

    now in your fragment

        public class Connections extends Fragment implements ListenFromActivity 
        { 
           public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
        {
          ((AnyActivity)Objects.requireNonNull(getActivity())).setActivityTab1Listener(Connections.this);
    
        }
        @Override
        public void doSearchInFragment(String SearchKey) {
        //pass to any network or local call.
        }
    }
    

提交回复
热议问题