title: How to do Filter listview in android?
body: <p><strong>How to do the Filter concept from Below design?</strong> I here by attached two screen designs.</p>
  <ol>
  <li>DashBoard Fragment -&gt; Having Listview with Base adapter.
  <a href="https://i.stack.imgur.com/bHJJ9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bHJJ9.png" alt="enter image description here" /></a></li>
  </ol>
  <p>The above ListView code is given Below</p>
  <h2>DashBoardRefactor</h2>
  <pre><code>public class DashBoardRefactor extends Fragment {
  
      public static ProgressDialog progress;
      public static List&lt;DashListModel&gt; dashRowList1 = new ArrayList&lt;DashListModel&gt;();
      public static View footerView;
      // @Bind(R.id.dashListView)
      public static ListView dashListView;
      int preCount = 2, scroll_Inc = 10, lastCount;
      boolean flag = true;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View v = inflater.inflate(R.layout.dashboard_fragment, container, false);
  
          ButterKnife.bind(this, v);
          setHasOptionsMenu(true);
          progress = new ProgressDialog(getActivity());
          dashListView = (ListView) v.findViewById(R.id.dashListView);
          footerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.dashboard_list_footer, null, false);
          dashListView.addFooterView(footerView);
          footerView.setVisibility(View.GONE);
          dashRowList1.clear();
          dashboardViewTask();
  
          dashListView.setOnScrollListener(new EndlessScrollListener(getActivity(), dashListView, footerView));
          return v;
      }
  
      public void dashboardViewTask() {
          progress.setMessage(&quot;Loading...&quot;);
          progress.setCanceledOnTouchOutside(false);
          progress.setCancelable(false);
          progress.show();
          //    footerView.setVisibility(View.VISIBLE);
          Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
          Log.e(&quot;candidate_id&quot;, &quot;candidate_id----&gt;&quot; + SessionStores.getBullHornId(getActivity()));
          params.put(&quot;candidate_id&quot;, SessionStores.getBullHornId(getActivity()));
          params.put(&quot;employmentPreference&quot;, SessionStores.getEmploymentPreference(getActivity()));
          params.put(&quot;page&quot;, &quot;1&quot;);
          new DashBoardTask(getActivity(), params, dashListView, footerView);
      }
  
      @Override
      public void onCreateOptionsMenu(
              Menu menu, MenuInflater inflater) {
          if (menu != null) {
              menu.removeItem(R.id.menu_notify);
          }
          inflater.inflate(R.menu.menu_options, menu);
          MenuItem item = menu.findItem(R.id.menu_filter);
          item.setVisible(true);
          getActivity().invalidateOptionsMenu();
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle item selection
          switch (item.getItemId()) {
              case R.id.his__menu_accept:
                  Toast.makeText(getActivity(), &quot;clicked dashboard  menu accept&quot;, Toast.LENGTH_LONG).show();
                  return true;
              case R.id.menu_filter:
                  // click evnt for filter
                  Toast.makeText(getActivity(), &quot;clicked dashboard  filter&quot;, Toast.LENGTH_LONG).show();
                  Intent filter_intent = new Intent(getActivity(), DashBoardFilterScreen.class);
                  startActivity(filter_intent);
                  getActivity().overridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out);
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
          }
      }
  
      public void onPause() {
          super.onPause();
          // dashboardViewTask();
      }
  }
  </code></pre>
  <p>DashBoardTask:</p>
  <pre><code>public class DashBoardTask {
     
      public static String candidateIdNo;
      public static Integer isBookmarked;
       public ListAdapter dashListAdapter;
      ListView dashListView;
      View footerView;
      String fromdate_formated = &quot;&quot;;
      String todate_formated = &quot;&quot;;
      private Context context;
      private JSONObject jObject = null;
      private String result, authorizationKey;
      private Map&lt;String, String&gt; params;
  
      public DashBoardTask(Context context, Map&lt;String, String&gt; params, ListView dashListView, View footerView) {
          this.context = context;
          Log.e(&quot;context &quot;, &quot;DashBoardTask: &quot; + context);
          this.dashListView = dashListView;
          Dashboard.dashRowList.clear();
          this.params = params;
          this.footerView = footerView;
          ResponseTask();
  
      }
  
      private void ResponseTask() {
          authorizationKey = Constants.ACCESS_TOKEN;
          new ServerResponse(ApiClass.getApiUrl(Constants.DASHBOARD_VIEW)).getJSONObjectfromURL(ServerResponse.RequestType.POST, params, authorizationKey, context, &quot;&quot;, new VolleyResponseListener() {
  
              @Override
              public void onError(String message) {
                  if (DashBoardRefactor.progress.isShowing()) {
                      DashBoardRefactor.progress.dismiss();
                  }
              }
  
              @Override
              public void onResponse(String response) {
                  String dateEnd = &quot;&quot;, startDate = &quot;&quot;;
                  result = response.toString();
                  try {
                      jObject = new JSONObject(result);
                      if (jObject != null) {
  
                          Integer totalJobList = jObject.getInt(&quot;page_count&quot;);
                          Integer total = jObject.getInt(&quot;total&quot;);
                          Integer count = jObject.getInt(&quot;count&quot;);
                          Integer start = jObject.getInt(&quot;start&quot;);
                          if (footerView.isShown() &amp;&amp; count == 0) {
                              footerView.setVisibility(View.GONE);
                          }
  
                          Integer Status = jObject.getInt(&quot;status&quot;);
                          if (Status == 1) {
                              SessionStores.savetotalJobList(totalJobList, context);
                             JSONArray dataObject = jObject.getJSONArray(&quot;data&quot;);
                              Dashboard.dashRowList.clear();
                              for (int i = 0; i &lt; dataObject.length(); i++) {
                                  Log.e(&quot;length&quot;, &quot;lenght-----&gt;&quot; + dataObject.length());
                                  JSONObject jobDetail = dataObject.getJSONObject(i);
                                  Log.e(&quot;jobDetail&quot;, &quot;jobDetail-----&gt;&quot; + jobDetail);
                                  Integer goalsName = jobDetail.getInt(&quot;id&quot;);
                                  String compnyTitle = jobDetail.getString(&quot;title&quot;);
                                  String description = jobDetail.getString(&quot;description&quot;);
                                  Integer salary = jobDetail.getInt(&quot;salary&quot;);
                                  String dateAdded = jobDetail.getString(&quot;dateAdded&quot;);
  
                                  if (jobDetail.getString(&quot;startDate&quot;) != null &amp;&amp; !jobDetail.getString(&quot;startDate&quot;).isEmpty() &amp;&amp; !jobDetail.getString(&quot;startDate&quot;).equals(&quot;null&quot;)) {
                                      startDate = jobDetail.getString(&quot;startDate&quot;);
                                  } else {
                                      Log.e(&quot;Task Null&quot;, &quot;Task Null----startDate-&gt;&quot;);
                                  }
                                  if (jobDetail.getString(&quot;dateEnd&quot;) != null &amp;&amp; !jobDetail.getString(&quot;dateEnd&quot;).isEmpty() &amp;&amp; !jobDetail.getString(&quot;dateEnd&quot;).equals(&quot;null&quot;)) {
                                      dateEnd = jobDetail.getString(&quot;dateEnd&quot;);
                                  } else {
                                      Log.e(&quot;Task Null&quot;, &quot;Task Null-----&gt;&quot;);
                                  }
                                  isBookmarked = jobDetail.getInt(&quot;isBookmarked&quot;);
                                  Integer startSalary = jobDetail.getInt(&quot;customFloat1&quot;);
                                  Integer endSalary = jobDetail.getInt(&quot;customFloat2&quot;);
  
                                  JSONObject cmpanyName = jobDetail.getJSONObject(&quot;clientCorporation&quot;);
                                  String compnyNamede = cmpanyName.getString(&quot;name&quot;);
                                  String city = jobDetail.getString(&quot;customText1&quot;);
  
                                  JSONObject candidateId = jobDetail.getJSONObject(&quot;clientContact&quot;);
                                  candidateIdNo = candidateId.getString(&quot;id&quot;);
  
  
                                  DashListModel dashListItem = new DashListModel();
  
                                  dashListItem.setDashCompanyName(compnyNamede);
                                  dashListItem.setDashJobDescription(description);
                                  dashListItem.setDashJobPosition(compnyTitle);
                                  dashListItem.setDashJobCity(city);
                                  // dashListItem.setDashJobState(state);
                                  dashListItem.setDashSalary(startSalary.toString());
                                  dashListItem.setDashJobAvailableDate(dateAdded);
                                  dashListItem.setDashId(goalsName.toString());
                                  dashListItem.setDashIsBookMarked(isBookmarked.toString());
                                  dashListItem.setDashEndSalary(endSalary.toString());
                                  dashListItem.setToDate(dateEnd);
  
                                  ////////////////////////////////////
  
  
                                  String fromDate = null, toDate = null, postedDate = null;
                                  if (startDate.length() &gt; 11) {
                                      Log.e(&quot;11&quot;, &quot;11----&gt;&quot;);
                                      fromDate = Utils.convertFromUnixDateAdded(startDate);
  
                                  } else if (startDate.length() == 10) {
  
                                      Log.e(&quot;10&quot;, &quot;10-----&gt;&quot;);
                                      fromDate = Utils.convertFromUnix(startDate);
  
                                  }
  
                                  if (dateEnd.length() &gt; 11) {
                                      Log.e(&quot;11&quot;, &quot;11----&gt;&quot;);
                                      toDate = Utils.convertFromUnixDateAdded(dateEnd);
                                  } else if (dateEnd.length() == 10) {
                                      Log.e(&quot;10&quot;, &quot;10-----&gt;&quot;);
                                      toDate = Utils.convertFromUnix(dateEnd);
                                  }
  
                                  if (dateAdded.length() &gt; 11) {
                                      Log.e(&quot;11&quot;, &quot;11----&gt;&quot;);
                                      postedDate = Utils.convertFromUnixDateAdded(dateAdded);
                                  } else if (dateAdded.length() == 10) {
                                      Log.e(&quot;10&quot;, &quot;10-----&gt;&quot;);
                                      postedDate = Utils.convertFromUnix(dateAdded);
                                  }
  
                                  try {
                                      if (!fromDate.isEmpty() || !fromDate.equalsIgnoreCase(&quot;null&quot;)) {
                                          String[] fromDateSplit = fromDate.split(&quot;/&quot;);
                                          String fromMonth = fromDateSplit[0];
                                          String fromDat = fromDateSplit[1];
                                          String fromYear = fromDateSplit[2];
                                          String fromMonthName = new DateFormatSymbols().getMonths()[Integer.parseInt(fromMonth) - 1];
                                          fromdate_formated = fromMonthName.substring(0, 3) + &quot; &quot; + fromDat + getDayOfMonthSuffix(Integer.parseInt(fromDat));
                                          Log.e(&quot;fromdate&quot;, &quot;fromdate----&gt;&quot; + fromDate);
                                          Log.e(&quot;toDate&quot;, &quot;toDate----&gt;&quot; + toDate);
  
                                          Log.e(&quot;fromMonth&quot;, &quot;fromMonth----&gt;&quot; + fromMonth);
                                          Log.e(&quot;fromDat&quot;, &quot;fromDat----&gt;&quot; + fromDat);
                                          Log.e(&quot;fromYear&quot;, &quot;fromYear----&gt;&quot; + fromYear);
  
                                      }
                                      if (!toDate.isEmpty() || !toDate.equalsIgnoreCase(&quot;null&quot;)) {
                                          String[] toDateSplit = toDate.split(&quot;/&quot;);
                                          String toMonth = toDateSplit[0];
                                          String toDat = toDateSplit[1];
                                          String toYear = toDateSplit[2];
                                          String toMonthName = new DateFormatSymbols().getMonths()[Integer.parseInt(toMonth) - 1];
  
                                          todate_formated = toMonthName.substring(0, 3) + &quot; &quot; + toDat + getDayOfMonthSuffix(Integer.parseInt(toDat)) + &quot; &quot; + toYear;
                                          Log.e(&quot;________________&quot;, &quot;--------------------&gt;&quot;);
  
                                          Log.e(&quot;toMonth&quot;, &quot;toMonth----&gt;&quot; + toMonth);
                                          Log.e(&quot;toDat&quot;, &quot;toDat----&gt;&quot; + toDat);
                                          Log.e(&quot;toYear&quot;, &quot;toYear----&gt;&quot; + toYear);
                                          Log.e(&quot;________________&quot;, &quot;--------------------&gt;&quot;);
                                          Log.e(&quot;toMonthName&quot;, &quot;toMonthName----&gt;&quot; + toMonthName);
  
                                      }
  
  
                                  } catch (Exception e) {
                                      e.printStackTrace();
                                  }
  
                                  dashListItem.setPostedDate(postedDate);
                                  dashListItem.setFromDate(fromdate_formated);
                                  dashListItem.setEndDate(todate_formated);
  
                                  /////////////////////////////////////////
                                  // Dashboard.dashRowList.add(dashListItem);
                                  DashBoardRefactor.dashRowList1.add(dashListItem);
  
                              }
  
                              // get listview current position - used to maintain scroll position
                              int currentPosition = dashListView.getFirstVisiblePosition();
                              dashListAdapter = new DashListAdapter(context, DashBoardRefactor.dashRowList1, dashListView);
                              dashListView.setAdapter(dashListAdapter);
                              ((BaseAdapter) dashListAdapter).notifyDataSetChanged();
  
                              if (currentPosition != 0) {
                                  // Setting new scroll position
                                  dashListView.setSelectionFromTop(currentPosition + 1, 0);
                              }
                          } else if (Status==0 &amp;&amp; count==0 &amp;&amp; start==0){
                              String Message = jObject.getString(&quot;message&quot;);
                              Utils.ShowAlert(context, Message);
                          }
                          if (footerView.isShown()) {
                              footerView.setVisibility(View.GONE);
                          }
                          //progress.dismiss();
                          if (DashBoardRefactor.progress.isShowing()) {
                              try {
                                  DashBoardRefactor.progress.dismiss();
                              } catch (Exception e) {
                                  e.printStackTrace();
                              }
                          }
                      }
  
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
  
              }
          });
      
      }
  
      }
  }
  </code></pre>
  <h2>DashListModel:</h2>
  <pre><code>public class DashListModel {
      private String dashCompanyName;
      private String dashJobPosition;
      private String dashJobPostedDate;
      private String dashJobDescription;
      private String dashSalary;
      private String dashJobCity;
      private String dashJobState;
      private String dashJobAvailableDate;
      private String dashId, dashIsBookmarked;
      private String dashEndSalary;
      private String toDate;
      private String postedDate, fromdate, enddate;
  
      public String getDashCompanyName() {
          return dashCompanyName;
      }
  
      public void setDashCompanyName(String dashCompanyName) {
          this.dashCompanyName = dashCompanyName;
      }
  
      public String getDashJobPosition() {
          return dashJobPosition;
      }
  
      public void setDashJobPosition(String dashJobPosition) {
          this.dashJobPosition = dashJobPosition;
      }
  
      public String getDashJobDescription() {
          return dashJobDescription;
      }
  
      public void setDashJobDescription(String dashJobDescription) {
          this.dashJobDescription = dashJobDescription;
      }
  
      public String getDashJobPostedDate() {
          return dashJobPostedDate;
      }
  
      public void setDashJobPostedDate(String dashJobPostedDate) {
          this.dashJobPostedDate = dashJobPostedDate;
      }
  
      public String getDashSalary() {
          return dashSalary;
      }
  
      public void setDashSalary(String dashSalary) {
          this.dashSalary = dashSalary;
      }
  
      public String getDashJobCity() {
          return dashJobCity;
      }
  
      public void setDashJobCity(String dashJobCity) {
          this.dashJobCity = dashJobCity;
      }
  
  
     /* public String getDashJobState() {
          return dashJobState;
      }
  
      public void setDashJobState(String dashJobState) {
          this.dashJobState = dashJobState;
      }*/
  
      public String getDashJobAvailableDate() {
          return dashJobAvailableDate;
      }
  
  
      public void setDashJobAvailableDate(String dashJobAvailableDate) {
          this.dashJobAvailableDate = dashJobAvailableDate;
      }
  
      public String getDashId() {
          return dashId;
      }
  
      public void setDashId(String dashId) {
          this.dashId = dashId;
      }
  
  
      public String getDashIsBookmarked() {
          return dashIsBookmarked;
      }
  
      public void setDashIsBookMarked(String dashIsBookmarked) {
          this.dashIsBookmarked = dashIsBookmarked;
      }
  
  
      public String getDashEndSalary() {
          return dashEndSalary;
      }
  
      public void setDashEndSalary(String dashEndSalary) {
          this.dashEndSalary = dashEndSalary;
      }
  
      public String getToDate() {
          return toDate;
      }
  
      public void setToDate(String toDate) {
          this.toDate = toDate;
      }
  
      public String getPostedDate() {
          return postedDate;
      }
  
      public void setPostedDate(String postedDate) {
          this.postedDate = postedDate;
      }
  
      public String getFromDate() {
          return fromdate;
      }
  
      public void setFromDate(String fromdate) {
          this.fromdate = fromdate;
      }
  
      public String getEndDate() {
          return enddate;
      }
  
      public void setEndDate(String enddate) {
          this.enddate = enddate;
      }
  </code></pre>
  <h2>DashListAdapter:</h2>
  <p>package com.peoplecaddie.adapter;</p>
  <p>public class DashListAdapter extends BaseAdapter {</p>
  <pre><code>    public static ListView dashListView;
      Context c;
      private LayoutInflater inflater;
      private List&lt;DashListModel&gt; dashRowList;
  
  
      public DashListAdapter(Context c, List&lt;DashListModel&gt; dashRowList, ListView dashListView) {
          this.c = c;
          this.dashListView = dashListView;
          this.dashRowList = dashRowList;
      }
  
      @Override
      public int getCount() {
          return this.dashRowList.size();
      }
  
      @Override
      public Object getItem(int position) {
          return dashRowList.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          final ViewHolder dashHolder;
          if (inflater == null)
              inflater = (LayoutInflater) c
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          if (convertView == null)
              convertView = inflater.inflate(R.layout.dashboard_jobdetails_list, null);
  
          final DashListModel dashModel = dashRowList.get(position);
          dashHolder = new ViewHolder(convertView);
  
  
          dashHolder.dash_company_name.setText(dashModel.getDashCompanyName());
          dashHolder.dash_position_name.setText(dashModel.getDashJobPosition());
          dashHolder.dash_posted_date.setText(dashModel.getPostedDate());
          dashHolder.dash_job_description.setText(Utils.stripHtml(dashModel.getDashJobDescription()));
          dashHolder.dash_salary.setText(dashModel.getDashSalary() + &quot; - &quot; + dashModel.getDashEndSalary());
          dashHolder.dash_available_date.setText(dashModel.getFromDate() + &quot; - &quot; + dashModel.getEndDate());
          dashHolder.book_jobCity.setText(dashModel.getDashJobCity());
          if (dashModel.getDashIsBookmarked().equalsIgnoreCase(&quot;1&quot;)) {
              dashHolder.bookmark_img.setImageResource(R.drawable.bookmark);
          } else if (dashModel.getDashIsBookmarked().equalsIgnoreCase(&quot;0&quot;)) {
              dashHolder.bookmark_img.setImageResource(R.drawable.blue_tag_img);
          }
  
          dashHolder.bookmark_img.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View view) {
                  if (dashModel.getDashIsBookmarked().equalsIgnoreCase(&quot;0&quot;)) {
                      dashModel.setDashIsBookMarked(&quot;1&quot;);
                      Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                      params.put(&quot;candidate_id&quot;, SessionStores.getBullHornId(c));
                      params.put(&quot;joborder_id&quot;, dashModel.getDashId());
                      BackGroundTasks bookmark_add_bg_tasks = new BackGroundTasks(c, new JSONObject(params), Constants.BOOKMARK_ADD_TAG);
                      bookmark_add_bg_tasks.ResponseTask(new BackGroundTasks.VolleyCallbackOnEdit() {
                          @Override
                          public void onSuccess(String result) {
                              String resp_resultsd = result;
                              Log.e(&quot;insidecallback&quot;, &quot; bookmark_add_bg_tasks-----&gt;&quot; + resp_resultsd);
                              // finish();
                              dashHolder.bookmark_img.setImageResource(R.drawable.bookmark);
                              notifyDataSetChanged();
                          }
                      });
  
                  } else if (dashModel.getDashIsBookmarked().equalsIgnoreCase(&quot;1&quot;)) {
                      dashModel.setDashIsBookMarked(&quot;0&quot;);
                      Log.e(&quot;imgchange&quot;, &quot; imgchange&quot;);
  
                      Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                      params.put(&quot;candidate_id&quot;, SessionStores.getBullHornId(c));
                      params.put(&quot;joborder_id&quot;, dashModel.getDashId());
  
                      BackGroundTasks bookmark_delete_bg_tasks = new BackGroundTasks(c, new JSONObject(params), Constants.BOOKMARK_DELETE_TAG);
                      bookmark_delete_bg_tasks.ResponseTask(new BackGroundTasks.VolleyCallbackOnEdit() {
                          @Override
                          public void onSuccess(String result) {
                              String resp_resultsd = result;
                              Log.e(&quot;insidecallback&quot;, &quot; bookmark_delete_bg_tasks-----&gt;&quot; + resp_resultsd);
                              // finish();
                              dashHolder.bookmark_img.setImageResource(R.drawable.blue_tag_img);
                              notifyDataSetChanged();
                          }
                      });
                  }
  
              }
          });
  
          return convertView;
      }
  
  
      static class ViewHolder {
          @Bind(R.id.book_company_name)
          TextView dash_company_name;
           private RelativeLayout.LayoutParams viewLayParams;
              public ViewHolder(View view) {
              ButterKnife.bind(this, view);
  
  
          }
      }
  
  
  }
  </code></pre>
  <p>Clarification:</p>
  <ol>
  <li>How do to Filter while click the Filter Button On DashBoard Fragment. Please Suggest the way. I here by attached My Filter design also.</li>
  </ol>
  <p><strong>Dashboard Fragment--&gt; Filter Button-&gt; Filter screen-&gt; the Filtered results should view on DashBoard Fragment.</strong></p>
  <p><a href="https://i.stack.imgur.com/9kfyg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9kfyg.png" alt="enter image description here" /></a></p>
  <p><em><strong>Once click the apply Button Based on the input from Filter screen it filters the list view the result comes from back end team. I have to display that result on Dashboard Fragment.</strong></em></p>
  <p>Kindly please clarify this Filter concept.</p>