Exemplo n.º 1
0
 @Override
 public boolean onQueryTextChange(String s) {
   mAdapter.getFilter().filter(s);
   return true;
 }
Exemplo n.º 2
0
  public void fillData(int i) {
    Cursor mGroupsCursor = getUdobri(i);
    if (!mGroupsCursor.moveToFirst()) {
      Button button = (Button) v.findViewById(R.id.add_udob);
      button.setVisibility(View.VISIBLE);
      button.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              Intent intent = new Intent(getActivity(), AddUdobra_activity.class);
              startActivity(intent);
            }
          });
    }
    mAdapter =
        new ExpandableListAdapter(
            mGroupsCursor,
            getActivity(),
            R.layout.udobra_list_group,
            0, // child layout //add dynamically
            new String[] {AssetsHelper.NAME_UDOBRA},
            new int[] {R.id.btnBuy},
            new String[] {},
            new int[] {android.R.id.text1});
    listView.setAdapter(mAdapter);
    listView.setTextFilterEnabled(true);

    mAdapter.setFilterQueryProvider(
        new FilterQueryProvider() {
          @Override
          public Cursor runQuery(CharSequence charSequence) {

            assert db != null;
            Cursor c;
            if (filter == 0) {
              c =
                  db.query(
                      AssetsHelper.TABLENAME_UDOBRA,
                      new String[] {
                        "_id",
                        AssetsHelper.NAME_UDOBRA,
                        AssetsHelper.ID_UDOBRA,
                        AssetsHelper.FAVORITE
                      },
                      AssetsHelper.NAME_UDOBRA
                          + " like '%"
                          + charSequence.toString()
                          + "%' AND "
                          + AssetsHelper.DELETED_FLAG
                          + "<> 1",
                      null,
                      null,
                      null,
                      AssetsHelper.ADDED + " DESC");
            } else if (filter == 1) {
              c =
                  db.query(
                      AssetsHelper.TABLENAME_UDOBRA,
                      new String[] {
                        "_id",
                        AssetsHelper.NAME_UDOBRA,
                        AssetsHelper.ID_UDOBRA,
                        AssetsHelper.FAVORITE,
                        AssetsHelper.ADDED
                      },
                      AssetsHelper.FAVORITE
                          + "=? AND "
                          + AssetsHelper.DELETED_FLAG
                          + "<> 1 AND "
                          + AssetsHelper.NAME_UDOBRA
                          + " like '%"
                          + charSequence.toString()
                          + "%'",
                      new String[] {"1"},
                      null,
                      null,
                      AssetsHelper.ADDED + " DESC");
            } else if (filter == 2) {
              c =
                  db.query(
                      AssetsHelper.TABLENAME_UDOBRA,
                      new String[] {
                        "_id",
                        AssetsHelper.NAME_UDOBRA,
                        AssetsHelper.ID_UDOBRA,
                        AssetsHelper.ADDED,
                        AssetsHelper.FAVORITE
                      },
                      AssetsHelper.ADDED
                          + "=? AND "
                          + AssetsHelper.DELETED_FLAG
                          + "<> 1 AND "
                          + AssetsHelper.NAME_UDOBRA
                          + " like '%"
                          + charSequence.toString()
                          + "%'",
                      new String[] {String.valueOf(1)},
                      null,
                      null,
                      null);
            } else {
              c =
                  db.query(
                      AssetsHelper.TABLENAME_UDOBRA,
                      new String[] {
                        "_id",
                        AssetsHelper.NAME_UDOBRA,
                        AssetsHelper.ID_UDOBRA,
                        AssetsHelper.ADDED,
                        AssetsHelper.FAVORITE
                      },
                      "("
                          + AssetsHelper.ADDED
                          + "=? OR "
                          + AssetsHelper.FAVORITE
                          + "=?) AND "
                          + AssetsHelper.DELETED_FLAG
                          + "<> 1 AND "
                          + AssetsHelper.NAME_UDOBRA
                          + " like '%"
                          + charSequence.toString()
                          + "%'",
                      new String[] {String.valueOf(1), String.valueOf(1)},
                      null,
                      null,
                      AssetsHelper.ADDED + " DESC");
            }
            return c;
          }
        });
  }