title: how to filter the listview by using onOptionsItemSelected method in android?
body: <p>I am developing an android application ,In that i have 3 tabs namely,</p>
  
  <pre><code>             1.Invitation tab(it have the invitation listviews) 
               2.Event tab(it have the event listviewes)
               3.Groupchat tab(it have both invitation and event listviewes) 
  </code></pre>
  
  <p>I have a dropdown(that present on dashboard layout) in gropchat tab that have 3 items namely(All,Event,Invitation).Now my need is,I want to filter my Listviews in Groupchat tab based on Dropdown item click functionality(for example,when on tap "Event" item i need to display only the event listviewes).How can i achieve this,Please help me.</p>
  
  <p>My programming code is below,</p>
  
  <pre><code>public class GroupChatFragment extends Fragment {
  
  
      private Context context;
      private ListView chatListView;
      private TextView chatTitle;
      private TextView chatPlace;
      private TextView chatDate;
      private String dateResult;
      private List&lt;EventMO&gt; groupEventMoList = new ArrayList&lt;&gt;();
      private List&lt;EventMO&gt; eventMOs = new ArrayList&lt;&gt;();
      private List&lt;EventMO&gt; invitationMOs = new ArrayList&lt;&gt;();
      private EventDelegates eventDelegates = new EventDelegates();
      private Gson gson = new Gson();
      private ProgressDialog prgDialog;
      private ChatDisplayAdapter chatDisplayAdapter;
      private ListView GroupEventView;
      private SharedPreferences sharedpreferences;
      private TextView eventList;
      private MessageMO messageMO = new MessageMO();
  
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case R.id.all:
  
                  return true;
              case R.id.event:
  
                  return true;
              case R.id.invitation:
  
                  return true;
  
          }
          return super.onOptionsItemSelected(item);
      }
  
      public void Event() {
          context = getActivity().getApplicationContext();
          DatabaseHelper dbHelper = new DatabaseHelper(context);
          final UserMO userMO = dbHelper.getRingeeUserData(1);
          eventMOs = gson.fromJson(eventDelegates.getAllEventFromUser(userMO, context), new TypeToken&lt;List&lt;EventMO&gt;&gt;() {
          }.getType());
          List&lt;EventMO&gt; groupEventMOList = new ArrayList&lt;&gt;();
  
          for (EventMO eventMO : eventMOs) {
              groupEventMOList.add(eventMO);
  
          }
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          final View view = inflater.inflate(R.layout.chatwindow_tab, container, false);
          context = getActivity().getApplicationContext();
          sharedpreferences = context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME,
                  Context.MODE_PRIVATE);
          DatabaseHelper dbHelper = new DatabaseHelper(context);
          final UserMO userMO = dbHelper.getRingeeUserData(1);
          prgDialog = new ProgressDialog(getActivity());
          prgDialog.setMessage("Please wait...");
          // Set Cancelable as False
          prgDialog.setCancelable(false);
          prgDialog.show();
          //inviation group for user
          new AsyncTask&lt;Void, Void, List&lt;EventMO&gt;&gt;() {
              @Override
              protected List&lt;EventMO&gt; doInBackground(Void... arg0) {
                  eventMOs = gson.fromJson(eventDelegates.getAllEventFromUser(userMO, context), new TypeToken&lt;List&lt;EventMO&gt;&gt;() {
                  }.getType());
                  invitationMOs = gson.fromJson(eventDelegates.getAllEventForUser(userMO, context), new TypeToken&lt;List&lt;EventMO&gt;&gt;() {
                  }.getType());
                  List&lt;EventMO&gt; groupEventMOList = new ArrayList&lt;&gt;();
  
                  for (EventMO eventMO : eventMOs) {
                      groupEventMOList.add(eventMO);
  
                  }
                  for (EventMO eventMO : invitationMOs) {
                      groupEventMOList.add(eventMO);
  
                  }
                  return groupEventMOList;
              }
  
              @Override
              protected void onPostExecute(List&lt;EventMO&gt; groupEventMOList) {
                  groupEventMoList = groupEventMOList;
                  prgDialog.dismiss();
                  DatabaseHelper dbHelper = new DatabaseHelper(context);
                  //long totalInsertion = dbHelper.insertUserRelationTable(userMOs);
                  //Toast.makeText(context, "total userMos size " + userMOs.size() + "total db insertion size " + totalInsertion, Toast.LENGTH_LONG).show();
                  GroupEventView = (ListView) view.findViewById(R.id.chat_list_view);
                  chatDisplayAdapter = new ChatDisplayAdapter();
                  GroupEventView.setAdapter(chatDisplayAdapter);
                  GroupEventView.setItemsCanFocus(true);
                  GroupEventView.setTextFilterEnabled(true);
                  GroupEventView.setOnItemClickListener(GroupEventView.getOnItemClickListener());
              }
          }.execute(null, null, null);
          return view;
      }
  
  
      private class ChatDisplayAdapter extends BaseAdapter {
  
          private LayoutInflater mInflater;
  
          public ChatDisplayAdapter() {
              mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          }
  
          @Override
          public int getCount() {
              return groupEventMoList.size();
          }
  
          @Override
          public Object getItem(int position) {
              return groupEventMoList.get(position);
          }
  
          @Override
          public long getItemId(int id) {
              // for sqllite management
              return 0;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              if (convertView == null) {
                  convertView = mInflater.inflate(R.layout.chatwindow, null);
                  convertView.setClickable(true);
                  convertView.setFocusable(true);
  
                  chatTitle = (TextView) convertView.findViewById(R.id.chat_title);
                  chatPlace = (TextView) convertView.findViewById(R.id.event_place);
                  chatDate = (TextView) convertView.findViewById(R.id.event_date);
                  chatPlace.setTextColor(getResources().getColor(R.color.black));
                  chatDate.setTextColor(getResources().getColor(R.color.black));
                  chatTitle.setTextColor(getResources().getColor(R.color.black));
                  chatPlace.setText(groupEventMoList.get(position).getPlace());
                  String actualDate = groupEventMoList.get(position).getEventDate();
                  //chatDate.setText(groupEventMoList.get(position).getEventDate());
                  try {
                      //date format changed here
                      Date formatDate = new SimpleDateFormat("yyyy-MM-dd").parse(actualDate);
                      dateResult = new SimpleDateFormat("dd-MM-yyyy").format(formatDate);
                  } catch (ParseException e) {
  
                      e.printStackTrace();
                  }
                  chatDate.setText(dateResult);
                  chatTitle.setText(groupEventMoList.get(position).getText());
                  convertView.setTag(position);
                  View v = convertView.findViewById(R.id.chat_window_single);
                  v.getRootView().setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Log.i("position", v.getTag().toString());
                          Intent groupAct = new Intent(context, GroupChatActivity.class);
                          groupAct.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                          groupAct.putExtra("eventMo", groupEventMoList.get(Integer.parseInt(v.getTag().toString())));
                          startActivity(groupAct);
                      }
  
                  });
              }
              return convertView;
          }
      }
  } 
  </code></pre>