title: Spinner item selection using adapter
body: <p>I created an <code>actvity</code> and have three tabs. In the third tab, there is a <code>spinner</code>. I'm listing two list <code>PAYMENTS</code> and <code>EXPENSE</code> from <code>API</code> call to <code>cardviews</code>. Initially the two list will show mixed. The <code>spinner</code> contains "<code>ALL"</code>. <code>PAYMENT</code> and <code>EXPENSE</code>. Whenever I selected <code>ALL</code>, It should normally <code>list</code> default <code>list</code>. <code>PAYMENT</code> option should show payments <code>list</code> only and expense should show expense only.  </p>
  
  <p><strong>Screenshot</strong>  </p>
  
  <p><a href="https://i.stack.imgur.com/uHT56.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uHT56.png" alt="enter image description here"></a></p>
  
  <pre><code>    //My whole class
  
  
  
  
  
  
     public class Approvals extends AppCompatActivity {
  
        static TextView startDate,endDate;
          private SectionsPagerAdapter mSectionsPagerAdapter;
  
          private ViewPager mViewPager;
  
          static ArrayList&lt;AsyncTask&gt; asyncTasks=new ArrayList&lt;&gt;();
          final static String ALL="All",PAYMENTS="Payments",EXPENSES="Expenses";
          String[] Pay = { "Payment", "Expense" };
  
          static CustomAdapter aadapter;
          static CustomAdapter padapter;
          static CustomAdapter eadapter;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_approvals);
  
              Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
              setSupportActionBar(toolbar);
  
              mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  
  
              mViewPager = (ViewPager) findViewById(R.id.container);
              mViewPager.setAdapter(mSectionsPagerAdapter);
              mViewPager.setOffscreenPageLimit(2);
  
              TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
              tabLayout.setupWithViewPager(mViewPager);
  
  
  
  
          }
  
           static SearchView searchView;
      static ArrayList&lt;ListView&gt; lists=new ArrayList&lt;&gt;();
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
  
              getMenuInflater().inflate(R.menu.menu_home_search, menu);
              searchView=(SearchView) menu.findItem(R.id.menu_search).getActionView();
              searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                  @Override
                  public boolean onQueryTextSubmit(String query) {
                      return false;
                  }
                  @Override
                  public boolean onQueryTextChange(String newText) {
  
                      final TabLayout tabHost = (TabLayout) findViewById(R.id.tabs);
                      for(int i=lists.size()-1;i&gt;=0;i--) {
                          final int Fi=i;
                          CustomAdapter adapter = (CustomAdapter) lists.get(i).getAdapter();
                          if (adapter != null) {//for searching
                              adapter.getFilter(Arrays.asList(1, 3, 7)).filter(searchView.getQuery().toString().trim());/*,new Filter.FilterListener() {
                                  public void onFilterComplete(int count) {
                                      if(count&gt;0){
                                          try {
                                              tabHost.getTabAt(Fi).select();
                                          }
                                          catch (Exception e){
                                            Common.toastMessage(InvoiceSummary.this,e.getMessage());
                                          }
                                      }
                                  }
                              });*/
                          }
                      }
                      return false;
                  }
              });
              return true;
          }
  
          static ArrayList&lt;ListView&gt; pre=new ArrayList&lt;&gt;();
  
  
  
          public static class PlaceholderFragment extends Fragment {
  
  
              private static final String ARG_SECTION_NUMBER = "section_number";
  
              public PlaceholderFragment() {
              }
  
              public static PlaceholderFragment newInstance(int sectionNumber) {
                  PlaceholderFragment fragment = new PlaceholderFragment();
                  Bundle args = new Bundle();
                  args.putInt(ARG_SECTION_NUMBER, sectionNumber);
                  fragment.setArguments(args);
                  return fragment;
              }
  
              @Override
              public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                                       Bundle savedInstanceState) {
  
  
  
  
  
                  final View rootView = inflater.inflate(R.layout.fragment_previous, container, false);
                  final LinearLayout fragmentLinear=(LinearLayout)rootView.findViewById(R.id.fragment_linear);
  
                  final ListView invoiceList=(ListView)rootView.findViewById(R.id.invoice_list);
                  pre.add(invoiceList);
  
  
  
  
  
  
                  if(getArguments().getInt(ARG_SECTION_NUMBER)==1) {//date-wise
  
  
                      final View invoiceHeader = inflater.inflate(R.layout.item_previous_header, null);
                      fragmentLinear.addView(invoiceHeader);
                      (invoiceHeader.findViewById(R.id.dates_layout)).setVisibility(View.VISIBLE);
                      startDate = (TextView) invoiceHeader.findViewById(R.id.start_date);
                      endDate = (TextView) invoiceHeader.findViewById(R.id.end_date);
  
                      List&lt;String&gt; options = new ArrayList&lt;String&gt;();
                      options.add(ALL);
                      options.add(PAYMENTS);
                      options.add(EXPENSES);
  
                      final Spinner spinner = (Spinner) rootView.findViewById(R.id.spinner1);
                      ArrayAdapter&lt;String&gt; dataAdapter = new ArrayAdapter&lt;String&gt;(this.getActivity(), android.R.layout.simple_spinner_item, options);
  
  
  
                      dataAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                      dataAdapter.setDropDownViewResource(R.layout.item_spinner);
                      spinner.setAdapter(dataAdapter);
  
  
  
  
  
  
  
  
                      Calendar c = Calendar.getInstance();
                      c.add(Calendar.MONTH, -1);
                      Calendar today = Calendar.getInstance();
  
                      SimpleDateFormat formatted = new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
                      startDate.setText(formatted.format(c.getTime()));
                      endDate.setText(formatted.format(today.getTime()));
                      getDateWiseInvoices(rootView,invoiceHeader,invoiceList);
                      View.OnClickListener onClickListener=new View.OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              final TextView requiredDate=(TextView)v;
                              final String oldText=requiredDate.getText().toString();
                              final Calendar today = Calendar.getInstance();
                              final Calendar selectedDate=Calendar.getInstance();
                              DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
                                  @Override
                                  public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                                      selectedDate.set(Calendar.YEAR, year);
                                      selectedDate.set(Calendar.MONTH, monthOfYear);
                                      selectedDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  
                                      //Setting display text-------
                                      SimpleDateFormat formatted = new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
                                      requiredDate.setText(formatted.format(selectedDate.getTime()));
                                      //Validation--------------
                                      if(!startDate.getText().toString().equals(getResources().getString(R.string.start_date))
                                              &amp;&amp;!endDate.getText().toString().equals(getResources().getString(R.string.end_date))){
                                          try {
                                              Date sDate=formatted.parse(startDate.getText().toString());
                                              Date eDate=formatted.parse(endDate.getText().toString());
                                              if(sDate.after(eDate)){
                                                  Common.toastMessage(getContext(),R.string.give_valid);
                                                  requiredDate.setText(oldText);
                                                  return;
                                              }
                                          } catch (ParseException e) {
                                              requiredDate.setText(oldText);
                                              return;
                                          }
                                          getDateWiseInvoices(rootView,invoiceHeader,invoiceList);
                                      }
                                  }
                              };
                              new DatePickerDialog(getContext(), dateSetListener, today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH)).show();
  
                          }
                      };
                      startDate.setOnClickListener(onClickListener);
                      endDate.setOnClickListener(onClickListener);
                  }
                  return rootView;
              }
  
              void getDateWiseInvoices(final View rootView,final View invoiceHeader,final ListView invoiceList){
  
  
                  (rootView.findViewById(R.id.no_items)).setVisibility(View.GONE);
  
                  (rootView.findViewById(R.id.list_card)).setVisibility(View.GONE);
                  invoiceList.setAdapter(null);
  
  
                  final Common common = new Common();
                  String webService = "/API/Approver/GetPreviousApprovalsInfo";
                  String postData = "{\"FromDate\":\"" + startDate.getText().toString() + "\",\"ToDate\":\"" + endDate.getText().toString() + "\"}";
                  AVLoadingIndicatorView loadingIndicator = (AVLoadingIndicatorView) rootView.findViewById(R.id.loading_indicator);
                  String[] dataColumns = {};
                  Runnable postThread = new Runnable() {
                      @Override
                      public void run() {
                          try {
                              JSONArray invoices = new JSONArray(common.json);
                              if(invoices.length()==0){
                                  (rootView.findViewById(R.id.no_items)).setVisibility(View.VISIBLE);
                                  return;
                              }
                              ArrayList&lt;String[]&gt; invoiceListData = new ArrayList&lt;&gt;();
                              for (int i = 0; i &lt; invoices.length(); i++) {
                                  JSONObject jsonObject1 = invoices.getJSONObject(i);
                                  String[] data = new String[8];
                                  data[0] = jsonObject1.getString("ID");
                                  data[1] = jsonObject1.getString("EntryNo");
                                  data[2] = jsonObject1.getString("Company");
                                  data[3] = jsonObject1.getString("Date");
                                  data[4] = jsonObject1.getString("PaymentMode");
                                  data[5] = jsonObject1.getString("Amount");
                                  data[6] = jsonObject1.getString("Type");
                                  data[7] = jsonObject1.getString("ApprovalDate");
  
  
                                  invoiceListData.add(data);
                              }
  
                              CustomAdapter adapter = new CustomAdapter(getContext(), invoiceListData, Common.PREVIOUSPAYMENTS);
                              invoiceList.setAdapter(adapter);
                              (rootView.findViewById(R.id.list_card)).setVisibility(View.VISIBLE);
  
  
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
  
  
  
                      }
                  };
  
                  Runnable postThreadFailed = new Runnable() {
                      @Override
                      public void run() {
                          Common.toastMessage(getContext(), R.string.failed_server);
                      }
                  };
  
                  common.AsynchronousThread(getContext(),
                          webService,
                          postData,
                          loadingIndicator,
                          dataColumns,
                          postThread,
                          postThreadFailed);
                  asyncTasks.add(common.asyncTask);
  
  
              }
  
             SearchView searchView;
  
  
          }
  
          public static class SectionsPagerAdapter extends FragmentPagerAdapter {
  
              public SectionsPagerAdapter(FragmentManager fm) {
                  super(fm);
              }
  
              @Override
              public Fragment getItem(int position) {
  
                  return PlaceholderFragment.newInstance(position + 1);
              }
  
              @Override
              public int getCount() {
  
                  return 1;
              }
  
              @Override
              public CharSequence getPageTitle(int position) {
                  switch (position) {
  
                      case 1:
                          return "Date wise";
                  }
                  return null;
              }
          }
  
      }
  
  
  
  
  
  
      //How to make display seperate list using adapter call when pressing spinner items.
  </code></pre>
  
  <p>//My adapter class</p>
  
  <pre><code>public class CustomAdapter extends BaseAdapter {
      private Context adapterContext;
      public static LayoutInflater inflater=null;
      private ArrayList&lt;String[]&gt; objects;
      private String calledFrom;
      private SimpleDateFormat formatted;
      private Calendar cal;
      CustomAdapter(Context context, ArrayList&lt;String[]&gt; objects, String calledFrom) {
  
          initialization(context, objects, calledFrom);
      }
      void initialization(Context context, ArrayList&lt;String[]&gt; objects, String calledFrom){
          adapterContext=context;
          inflater = ( LayoutInflater )context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          this.objects=objects;
          this.filteredObjects=objects;
          this.calledFrom=calledFrom;
  
      }
      @Override
      public int getCount() {
          return filteredObjects.size();
      }
  
      @Override
      public Object getItem(int position) {
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      private class Holder {
  
          TextView entryN,compN,payD,payM,payA,payT,appD;
  
  
      }
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          Holder holder;
          final int fPos=position;
          switch (calledFrom) {
  
  
            case Common.PREVIOUSPAYMENTS:
                  if (convertView == null) {
                      holder = new Holder();
                      convertView = inflater.inflate(R.layout.item_previous_approvals, null);
                      holder.entryN = (TextView) convertView.findViewById(R.id.entry_no);
                      holder.compN=(TextView)convertView.findViewById(R.id.company_name);
                      holder.payD=(TextView)convertView.findViewById(R.id.payment_date);
                      holder.payM=(TextView)convertView.findViewById(R.id.payment_mode);
                      holder.payA=(TextView)convertView.findViewById(R.id.payment_amount);
                      holder.payT=(TextView)convertView.findViewById(R.id.payment_type);
                      holder.appD=(TextView)convertView.findViewById(R.id.approval_date);
                      convertView.setTag(holder);
                  } else {
                      holder = (Holder) convertView.getTag();
                  }
  
  //              holder.paidAmount.setText((filteredObjects.get(position)[6].equals("null")?"-":adapterContext.getResources().getString(R.string.paid_amount,filteredObjects.get(position)[6])));
                  holder.entryN.setText((filteredObjects.get(position)[1].equals("null")?"-":filteredObjects.get(position)[1]));
                  holder.compN.setText((filteredObjects.get(position)[2].equals("null")?"-":filteredObjects.get(position)[2]));
                  holder.payD.setText((filteredObjects.get(position)[3].equals("null")?"-":filteredObjects.get(position)[3]));
                  holder.payM.setText((filteredObjects.get(position)[4].equals("null")?"-":filteredObjects.get(position)[4]));
                  holder.payA.setText((filteredObjects.get(position)[5].equals("null")?"-":adapterContext.getResources().getString(R.string.paid_amount,filteredObjects.get(position)[5])));
                  holder.payT.setText((filteredObjects.get(position)[6].equals("null")?"-":filteredObjects.get(position)[6]));
                  holder.appD.setText((filteredObjects.get(position)[7].equals("null")?"-":adapterContext.getResources().getString(R.string.Ap_date,filteredObjects.get(position)[7])));
                  break;
  
  
  
  
  
  
  
  
  
  
          }
          return convertView;
      }
  
  
      private ItemFilter mFilter = new ItemFilter();
      private ArrayList&lt;String[]&gt; filteredObjects;
      private List&lt;Integer&gt; dataItemPosition;
      Filter getFilter(List&lt;Integer&gt; dataItem) {
          dataItemPosition=dataItem;
          return mFilter;
      }
      private class ItemFilter extends Filter {
          @Override
          protected FilterResults performFiltering(CharSequence constraint) {
              String filterString = constraint.toString().toLowerCase();
              FilterResults results = new FilterResults();
              int count = objects.size();
              final ArrayList&lt;String[]&gt; filteredList = new ArrayList&lt;String[]&gt;(count);
  
              for (int i = 0; i &lt; count; i++) {
                  for(int j=0;j&lt;dataItemPosition.size();j++) {
                      if (objects.get(i)[dataItemPosition.get(j)].toLowerCase().contains(filterString)) {
                          filteredList.add(objects.get(i));
                          break;//found at least one item
                      }
                  }
              }
  
              results.values = filteredList;
              results.count = filteredList.size();
              return results;
          }
  
          @SuppressWarnings("unchecked")
          @Override
          protected void publishResults(CharSequence constraint, FilterResults results) {
              filteredObjects = (ArrayList&lt;String[]&gt;) results.values;
              notifyDataSetChanged();
          }
      }
  }
  </code></pre>