Implementing Search Function to search in ListView by specific TextViewhow to implement search in custom listview in android?How do I center text horizontally and vertically in a TextView?Lazy load of images in ListViewHow to display HTML in TextView?How do I make links in a TextView clickable?Set TextView style (bold or italic)ListView ImageButton Set RingtoneAdapter showing the wrong images while using Fresco librarySaving ToggleButton state in ListView by using SharedPreferencesScrolling lagged after applying the typeface in the Recycler view itemsListView mixing up values when scrolling

What does a red v with a dot above mean in the Misal rico de Cisneros (Spain, 1518)?

As a DM, how to avoid unconscious metagaming when dealing with a high AC character?

How would someone destroy a black hole that’s at the centre of a planet?

Bob's unnecessary trip to the shops

GPIO and Python - GPIO.output() not working

Why do they not say "The Baby"

Project Euler, problem # 9, Pythagorean triplet

Alternatives to using writing paper for writing practice

Are there any double stars that I can actually see orbit each other?

Why limit to revolvers?

How might the United Kingdom become a republic?

How can we better understand multiplicative inverse modulo something?

Why do candidates not quit if they no longer have a realistic chance to win in the 2020 US presidents election

Does ability to impeach an expert witness on science or scholarship go too far?

Doing research in academia and not liking competition

Is the Gungan military rank of Bombad General roughly equivalent in stature to General in other militaries?

Why is dry soil hydrophobic? Bad gardener paradox

What exactly is the Tension force?

What caused Windows ME's terrible reputation?

Access files in Home directory from live mode

How can an advanced civilization forget how to manufacture its technology?

Why does the trade federation become so alarmed upon learning the ambassadors are Jedi Knights?

Are there examples of Tanaim, Amoraim,Rishonim, Achronim using secular sources for Limud Torah?

Add region constraint to Graphics



Implementing Search Function to search in ListView by specific TextView


how to implement search in custom listview in android?How do I center text horizontally and vertically in a TextView?Lazy load of images in ListViewHow to display HTML in TextView?How do I make links in a TextView clickable?Set TextView style (bold or italic)ListView ImageButton Set RingtoneAdapter showing the wrong images while using Fresco librarySaving ToggleButton state in ListView by using SharedPreferencesScrolling lagged after applying the typeface in the Recycler view itemsListView mixing up values when scrolling






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















[Auction List Image][1] I am trying to implement a search function to search through the ListView by a specific TextView which is the ItemName TextView as shown in the image such as "Adidas Shoes" & "Nike Shoes" .That TextView is id as txtName. Currently, with these codes, there is no error, but the search function is not doing anything. How do I implement the search to actually search by looking through the txtName TextView?



Adapter:



public class AuctionListAdapter extends BaseAdapter implements Filterable 

ValueFilter valueFilter;


private Context context;
private int layout;
private ArrayList<Model> auctionList;




public AuctionListAdapter(Context context, int layout, ArrayList<Model> auctionList)
this.context = context;
this.layout = layout;
this.auctionList = auctionList;


@Override
public int getCount()
return auctionList.size();


@Override
public Object getItem(int position)
return auctionList.get(position);



@Override
public long getItemId(int position)
return position;


@Override
public Filter getFilter()
if (valueFilter == null)
valueFilter = new ValueFilter();

return valueFilter;


private class ValueFilter extends Filter
@Override
protected FilterResults performFiltering(CharSequence constraint)
FilterResults results = new FilterResults();

if (constraint != null && constraint.length() > 0)
ArrayList<Model> filterList = new ArrayList<Model>();
for (int i = 0; i < auctionList.size(); i++)
if ((auctionList.get(i).getName().toUpperCase())
.contains(constraint.toString().toUpperCase()))
Model model = new Model(auctionList.get(i).getId(),auctionList.get(i).getName(),
auctionList.get(i).getDescription(),auctionList.get(i).getPrice(),auctionList.get(i).getDuration()
,auctionList.get(i).getImage());
filterList.add(model);




results.count = filterList.size();
results.values = filterList;
else
results.count = auctionList.size();
results.values = auctionList;

return results;



@Override
protected void publishResults(CharSequence constraint,
FilterResults results)
auctionList = (ArrayList<Model>) results.values;
notifyDataSetChanged();





private class ViewHolder
ImageView imageView;
TextView txtName,txtDescription,txtPrice,txtDuration;


@Override
public View getView(int position, View convertView, ViewGroup parent)
View row = convertView;
ViewHolder holder = new ViewHolder();

if(row == null)
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layout,null);
holder.txtName=row.findViewById(R.id.txtName);
holder.txtDescription=row.findViewById(R.id.txtDescription);
holder.txtPrice=row.findViewById(R.id.txtPrice);
holder.txtDuration=row.findViewById(R.id.txtDuration);
holder.imageView=row.findViewById(R.id.imgIcon);
row.setTag(holder);

else
holder = (ViewHolder)row.getTag();

Model model = auctionList.get(position);

holder.txtName.setText(model.getName());
holder.txtDescription.setText(model.getDescription());
holder.txtPrice.setText(model.getPrice());
holder.txtDuration.setText(model.getDuration());


byte[] auctionImage = model.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(auctionImage,0,auctionImage.length);
holder.imageView.setImageBitmap(bitmap);
return row;






AuctionList.java:



@Override
public boolean onCreateOptionsMenu(Menu menu)
getMenuInflater().inflate(R.menu.searchmenu,menu);

MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView)myActionMenuItem.getActionView();

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
@Override
public boolean onQueryTextSubmit(String text)

return false;


@Override
public boolean onQueryTextChange(String newText)
mAdapter.getFilter().filter(newText);
return false;

);


return super.onCreateOptionsMenu(menu);










share|improve this question
























  • Its not doing anything because you haven't write any code to make it work .SearchView does not filter data itself .

    – ADM
    Mar 26 at 6:52











  • Can you tell me how do I search by the TextView?

    – saap mong
    Mar 26 at 6:54











  • stackoverflow.com/questions/21827646/…

    – ADM
    Mar 26 at 6:55











  • Is there any ways that I can make minimal changes to my codes?

    – saap mong
    Mar 26 at 7:22

















0















[Auction List Image][1] I am trying to implement a search function to search through the ListView by a specific TextView which is the ItemName TextView as shown in the image such as "Adidas Shoes" & "Nike Shoes" .That TextView is id as txtName. Currently, with these codes, there is no error, but the search function is not doing anything. How do I implement the search to actually search by looking through the txtName TextView?



Adapter:



public class AuctionListAdapter extends BaseAdapter implements Filterable 

ValueFilter valueFilter;


private Context context;
private int layout;
private ArrayList<Model> auctionList;




public AuctionListAdapter(Context context, int layout, ArrayList<Model> auctionList)
this.context = context;
this.layout = layout;
this.auctionList = auctionList;


@Override
public int getCount()
return auctionList.size();


@Override
public Object getItem(int position)
return auctionList.get(position);



@Override
public long getItemId(int position)
return position;


@Override
public Filter getFilter()
if (valueFilter == null)
valueFilter = new ValueFilter();

return valueFilter;


private class ValueFilter extends Filter
@Override
protected FilterResults performFiltering(CharSequence constraint)
FilterResults results = new FilterResults();

if (constraint != null && constraint.length() > 0)
ArrayList<Model> filterList = new ArrayList<Model>();
for (int i = 0; i < auctionList.size(); i++)
if ((auctionList.get(i).getName().toUpperCase())
.contains(constraint.toString().toUpperCase()))
Model model = new Model(auctionList.get(i).getId(),auctionList.get(i).getName(),
auctionList.get(i).getDescription(),auctionList.get(i).getPrice(),auctionList.get(i).getDuration()
,auctionList.get(i).getImage());
filterList.add(model);




results.count = filterList.size();
results.values = filterList;
else
results.count = auctionList.size();
results.values = auctionList;

return results;



@Override
protected void publishResults(CharSequence constraint,
FilterResults results)
auctionList = (ArrayList<Model>) results.values;
notifyDataSetChanged();





private class ViewHolder
ImageView imageView;
TextView txtName,txtDescription,txtPrice,txtDuration;


@Override
public View getView(int position, View convertView, ViewGroup parent)
View row = convertView;
ViewHolder holder = new ViewHolder();

if(row == null)
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layout,null);
holder.txtName=row.findViewById(R.id.txtName);
holder.txtDescription=row.findViewById(R.id.txtDescription);
holder.txtPrice=row.findViewById(R.id.txtPrice);
holder.txtDuration=row.findViewById(R.id.txtDuration);
holder.imageView=row.findViewById(R.id.imgIcon);
row.setTag(holder);

else
holder = (ViewHolder)row.getTag();

Model model = auctionList.get(position);

holder.txtName.setText(model.getName());
holder.txtDescription.setText(model.getDescription());
holder.txtPrice.setText(model.getPrice());
holder.txtDuration.setText(model.getDuration());


byte[] auctionImage = model.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(auctionImage,0,auctionImage.length);
holder.imageView.setImageBitmap(bitmap);
return row;






AuctionList.java:



@Override
public boolean onCreateOptionsMenu(Menu menu)
getMenuInflater().inflate(R.menu.searchmenu,menu);

MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView)myActionMenuItem.getActionView();

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
@Override
public boolean onQueryTextSubmit(String text)

return false;


@Override
public boolean onQueryTextChange(String newText)
mAdapter.getFilter().filter(newText);
return false;

);


return super.onCreateOptionsMenu(menu);










share|improve this question
























  • Its not doing anything because you haven't write any code to make it work .SearchView does not filter data itself .

    – ADM
    Mar 26 at 6:52











  • Can you tell me how do I search by the TextView?

    – saap mong
    Mar 26 at 6:54











  • stackoverflow.com/questions/21827646/…

    – ADM
    Mar 26 at 6:55











  • Is there any ways that I can make minimal changes to my codes?

    – saap mong
    Mar 26 at 7:22













0












0








0








[Auction List Image][1] I am trying to implement a search function to search through the ListView by a specific TextView which is the ItemName TextView as shown in the image such as "Adidas Shoes" & "Nike Shoes" .That TextView is id as txtName. Currently, with these codes, there is no error, but the search function is not doing anything. How do I implement the search to actually search by looking through the txtName TextView?



Adapter:



public class AuctionListAdapter extends BaseAdapter implements Filterable 

ValueFilter valueFilter;


private Context context;
private int layout;
private ArrayList<Model> auctionList;




public AuctionListAdapter(Context context, int layout, ArrayList<Model> auctionList)
this.context = context;
this.layout = layout;
this.auctionList = auctionList;


@Override
public int getCount()
return auctionList.size();


@Override
public Object getItem(int position)
return auctionList.get(position);



@Override
public long getItemId(int position)
return position;


@Override
public Filter getFilter()
if (valueFilter == null)
valueFilter = new ValueFilter();

return valueFilter;


private class ValueFilter extends Filter
@Override
protected FilterResults performFiltering(CharSequence constraint)
FilterResults results = new FilterResults();

if (constraint != null && constraint.length() > 0)
ArrayList<Model> filterList = new ArrayList<Model>();
for (int i = 0; i < auctionList.size(); i++)
if ((auctionList.get(i).getName().toUpperCase())
.contains(constraint.toString().toUpperCase()))
Model model = new Model(auctionList.get(i).getId(),auctionList.get(i).getName(),
auctionList.get(i).getDescription(),auctionList.get(i).getPrice(),auctionList.get(i).getDuration()
,auctionList.get(i).getImage());
filterList.add(model);




results.count = filterList.size();
results.values = filterList;
else
results.count = auctionList.size();
results.values = auctionList;

return results;



@Override
protected void publishResults(CharSequence constraint,
FilterResults results)
auctionList = (ArrayList<Model>) results.values;
notifyDataSetChanged();





private class ViewHolder
ImageView imageView;
TextView txtName,txtDescription,txtPrice,txtDuration;


@Override
public View getView(int position, View convertView, ViewGroup parent)
View row = convertView;
ViewHolder holder = new ViewHolder();

if(row == null)
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layout,null);
holder.txtName=row.findViewById(R.id.txtName);
holder.txtDescription=row.findViewById(R.id.txtDescription);
holder.txtPrice=row.findViewById(R.id.txtPrice);
holder.txtDuration=row.findViewById(R.id.txtDuration);
holder.imageView=row.findViewById(R.id.imgIcon);
row.setTag(holder);

else
holder = (ViewHolder)row.getTag();

Model model = auctionList.get(position);

holder.txtName.setText(model.getName());
holder.txtDescription.setText(model.getDescription());
holder.txtPrice.setText(model.getPrice());
holder.txtDuration.setText(model.getDuration());


byte[] auctionImage = model.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(auctionImage,0,auctionImage.length);
holder.imageView.setImageBitmap(bitmap);
return row;






AuctionList.java:



@Override
public boolean onCreateOptionsMenu(Menu menu)
getMenuInflater().inflate(R.menu.searchmenu,menu);

MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView)myActionMenuItem.getActionView();

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
@Override
public boolean onQueryTextSubmit(String text)

return false;


@Override
public boolean onQueryTextChange(String newText)
mAdapter.getFilter().filter(newText);
return false;

);


return super.onCreateOptionsMenu(menu);










share|improve this question
















[Auction List Image][1] I am trying to implement a search function to search through the ListView by a specific TextView which is the ItemName TextView as shown in the image such as "Adidas Shoes" & "Nike Shoes" .That TextView is id as txtName. Currently, with these codes, there is no error, but the search function is not doing anything. How do I implement the search to actually search by looking through the txtName TextView?



Adapter:



public class AuctionListAdapter extends BaseAdapter implements Filterable 

ValueFilter valueFilter;


private Context context;
private int layout;
private ArrayList<Model> auctionList;




public AuctionListAdapter(Context context, int layout, ArrayList<Model> auctionList)
this.context = context;
this.layout = layout;
this.auctionList = auctionList;


@Override
public int getCount()
return auctionList.size();


@Override
public Object getItem(int position)
return auctionList.get(position);



@Override
public long getItemId(int position)
return position;


@Override
public Filter getFilter()
if (valueFilter == null)
valueFilter = new ValueFilter();

return valueFilter;


private class ValueFilter extends Filter
@Override
protected FilterResults performFiltering(CharSequence constraint)
FilterResults results = new FilterResults();

if (constraint != null && constraint.length() > 0)
ArrayList<Model> filterList = new ArrayList<Model>();
for (int i = 0; i < auctionList.size(); i++)
if ((auctionList.get(i).getName().toUpperCase())
.contains(constraint.toString().toUpperCase()))
Model model = new Model(auctionList.get(i).getId(),auctionList.get(i).getName(),
auctionList.get(i).getDescription(),auctionList.get(i).getPrice(),auctionList.get(i).getDuration()
,auctionList.get(i).getImage());
filterList.add(model);




results.count = filterList.size();
results.values = filterList;
else
results.count = auctionList.size();
results.values = auctionList;

return results;



@Override
protected void publishResults(CharSequence constraint,
FilterResults results)
auctionList = (ArrayList<Model>) results.values;
notifyDataSetChanged();





private class ViewHolder
ImageView imageView;
TextView txtName,txtDescription,txtPrice,txtDuration;


@Override
public View getView(int position, View convertView, ViewGroup parent)
View row = convertView;
ViewHolder holder = new ViewHolder();

if(row == null)
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layout,null);
holder.txtName=row.findViewById(R.id.txtName);
holder.txtDescription=row.findViewById(R.id.txtDescription);
holder.txtPrice=row.findViewById(R.id.txtPrice);
holder.txtDuration=row.findViewById(R.id.txtDuration);
holder.imageView=row.findViewById(R.id.imgIcon);
row.setTag(holder);

else
holder = (ViewHolder)row.getTag();

Model model = auctionList.get(position);

holder.txtName.setText(model.getName());
holder.txtDescription.setText(model.getDescription());
holder.txtPrice.setText(model.getPrice());
holder.txtDuration.setText(model.getDuration());


byte[] auctionImage = model.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(auctionImage,0,auctionImage.length);
holder.imageView.setImageBitmap(bitmap);
return row;






AuctionList.java:



@Override
public boolean onCreateOptionsMenu(Menu menu)
getMenuInflater().inflate(R.menu.searchmenu,menu);

MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView)myActionMenuItem.getActionView();

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
@Override
public boolean onQueryTextSubmit(String text)

return false;


@Override
public boolean onQueryTextChange(String newText)
mAdapter.getFilter().filter(newText);
return false;

);


return super.onCreateOptionsMenu(menu);







android listview searchview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 7:47







saap mong

















asked Mar 26 at 6:33









saap mongsaap mong

65 bronze badges




65 bronze badges












  • Its not doing anything because you haven't write any code to make it work .SearchView does not filter data itself .

    – ADM
    Mar 26 at 6:52











  • Can you tell me how do I search by the TextView?

    – saap mong
    Mar 26 at 6:54











  • stackoverflow.com/questions/21827646/…

    – ADM
    Mar 26 at 6:55











  • Is there any ways that I can make minimal changes to my codes?

    – saap mong
    Mar 26 at 7:22

















  • Its not doing anything because you haven't write any code to make it work .SearchView does not filter data itself .

    – ADM
    Mar 26 at 6:52











  • Can you tell me how do I search by the TextView?

    – saap mong
    Mar 26 at 6:54











  • stackoverflow.com/questions/21827646/…

    – ADM
    Mar 26 at 6:55











  • Is there any ways that I can make minimal changes to my codes?

    – saap mong
    Mar 26 at 7:22
















Its not doing anything because you haven't write any code to make it work .SearchView does not filter data itself .

– ADM
Mar 26 at 6:52





Its not doing anything because you haven't write any code to make it work .SearchView does not filter data itself .

– ADM
Mar 26 at 6:52













Can you tell me how do I search by the TextView?

– saap mong
Mar 26 at 6:54





Can you tell me how do I search by the TextView?

– saap mong
Mar 26 at 6:54













stackoverflow.com/questions/21827646/…

– ADM
Mar 26 at 6:55





stackoverflow.com/questions/21827646/…

– ADM
Mar 26 at 6:55













Is there any ways that I can make minimal changes to my codes?

– saap mong
Mar 26 at 7:22





Is there any ways that I can make minimal changes to my codes?

– saap mong
Mar 26 at 7:22












2 Answers
2






active

oldest

votes


















0














Create a private class inside your adapter



 /**
* Custom filter for Brand list
* Filter content in brand list according to the search text
*/
private class BrandFilter extends Filter

@Override
protected FilterResults performFiltering(CharSequence constraint)
FilterResults filterResults = new FilterResults();
if (constraint!=null && constraint.length()>0)
ArrayList<User> tempList = new ArrayList<User>();

// search content in Brand list
for (User user : brandList)
if (mList.getBrandName().toLowerCase().contains(constraint.toString().toLowerCase()))
tempList.add(user);



filterResults.count = tempList.size();
filterResults.values = tempList;
else
filterResults.count = friendList.size();
filterResults.values = friendList;


return filterResults;


/**
* Notify about filtered list to ui
* @param constraint text
* @param results filtered result
*/
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results)
filteredList = (ArrayList<User>) results.values;
notifyDataSetChanged();




Implement Filterable to your adapter , and write the following code to your Override function getfilter.



 if (brandFilter == null) 
Filter = new BrandFilter();


return friendFilter;


Just call this method inside your activity , on onQueryTextChange



 mAdapetr.getFilter().filter(newText);





share|improve this answer























  • What's the brandFilter may I ask?

    – saap mong
    Mar 26 at 7:07











  • @Override public Filter getFilter() if (brandFilter == null) Filter = new BrandFilter(); return friendFilter;

    – saap mong
    Mar 26 at 7:10











  • Hi I managed to make it work already. However, whenever i search,and then backspace the words, the listview doesnt refresh back to its original. How do I solve this?

    – saap mong
    Mar 26 at 7:48











  • you need to clear the list , and notify your adapter .

    – Mini Chip
    Mar 26 at 8:01











  • I have given the example form my code base . you can make the changes accordingly to your adapter . every time you write a query of anything , jus notify your adapter .

    – Mini Chip
    Mar 26 at 8:02


















0














For temp list :



 private ArrayList<Model> filteredList;


and in your constructor



this.filteredList = auctionList


while publishing result , /**
* Notify about filtered list to ui
* @param constraint text
* @param results filtered result
*/
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results)
filteredList = (ArrayList<Model>) results.values;
notifyDataSetChanged();






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55351067%2fimplementing-search-function-to-search-in-listview-by-specific-textview%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Create a private class inside your adapter



     /**
    * Custom filter for Brand list
    * Filter content in brand list according to the search text
    */
    private class BrandFilter extends Filter

    @Override
    protected FilterResults performFiltering(CharSequence constraint)
    FilterResults filterResults = new FilterResults();
    if (constraint!=null && constraint.length()>0)
    ArrayList<User> tempList = new ArrayList<User>();

    // search content in Brand list
    for (User user : brandList)
    if (mList.getBrandName().toLowerCase().contains(constraint.toString().toLowerCase()))
    tempList.add(user);



    filterResults.count = tempList.size();
    filterResults.values = tempList;
    else
    filterResults.count = friendList.size();
    filterResults.values = friendList;


    return filterResults;


    /**
    * Notify about filtered list to ui
    * @param constraint text
    * @param results filtered result
    */
    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence constraint, FilterResults results)
    filteredList = (ArrayList<User>) results.values;
    notifyDataSetChanged();




    Implement Filterable to your adapter , and write the following code to your Override function getfilter.



     if (brandFilter == null) 
    Filter = new BrandFilter();


    return friendFilter;


    Just call this method inside your activity , on onQueryTextChange



     mAdapetr.getFilter().filter(newText);





    share|improve this answer























    • What's the brandFilter may I ask?

      – saap mong
      Mar 26 at 7:07











    • @Override public Filter getFilter() if (brandFilter == null) Filter = new BrandFilter(); return friendFilter;

      – saap mong
      Mar 26 at 7:10











    • Hi I managed to make it work already. However, whenever i search,and then backspace the words, the listview doesnt refresh back to its original. How do I solve this?

      – saap mong
      Mar 26 at 7:48











    • you need to clear the list , and notify your adapter .

      – Mini Chip
      Mar 26 at 8:01











    • I have given the example form my code base . you can make the changes accordingly to your adapter . every time you write a query of anything , jus notify your adapter .

      – Mini Chip
      Mar 26 at 8:02















    0














    Create a private class inside your adapter



     /**
    * Custom filter for Brand list
    * Filter content in brand list according to the search text
    */
    private class BrandFilter extends Filter

    @Override
    protected FilterResults performFiltering(CharSequence constraint)
    FilterResults filterResults = new FilterResults();
    if (constraint!=null && constraint.length()>0)
    ArrayList<User> tempList = new ArrayList<User>();

    // search content in Brand list
    for (User user : brandList)
    if (mList.getBrandName().toLowerCase().contains(constraint.toString().toLowerCase()))
    tempList.add(user);



    filterResults.count = tempList.size();
    filterResults.values = tempList;
    else
    filterResults.count = friendList.size();
    filterResults.values = friendList;


    return filterResults;


    /**
    * Notify about filtered list to ui
    * @param constraint text
    * @param results filtered result
    */
    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence constraint, FilterResults results)
    filteredList = (ArrayList<User>) results.values;
    notifyDataSetChanged();




    Implement Filterable to your adapter , and write the following code to your Override function getfilter.



     if (brandFilter == null) 
    Filter = new BrandFilter();


    return friendFilter;


    Just call this method inside your activity , on onQueryTextChange



     mAdapetr.getFilter().filter(newText);





    share|improve this answer























    • What's the brandFilter may I ask?

      – saap mong
      Mar 26 at 7:07











    • @Override public Filter getFilter() if (brandFilter == null) Filter = new BrandFilter(); return friendFilter;

      – saap mong
      Mar 26 at 7:10











    • Hi I managed to make it work already. However, whenever i search,and then backspace the words, the listview doesnt refresh back to its original. How do I solve this?

      – saap mong
      Mar 26 at 7:48











    • you need to clear the list , and notify your adapter .

      – Mini Chip
      Mar 26 at 8:01











    • I have given the example form my code base . you can make the changes accordingly to your adapter . every time you write a query of anything , jus notify your adapter .

      – Mini Chip
      Mar 26 at 8:02













    0












    0








    0







    Create a private class inside your adapter



     /**
    * Custom filter for Brand list
    * Filter content in brand list according to the search text
    */
    private class BrandFilter extends Filter

    @Override
    protected FilterResults performFiltering(CharSequence constraint)
    FilterResults filterResults = new FilterResults();
    if (constraint!=null && constraint.length()>0)
    ArrayList<User> tempList = new ArrayList<User>();

    // search content in Brand list
    for (User user : brandList)
    if (mList.getBrandName().toLowerCase().contains(constraint.toString().toLowerCase()))
    tempList.add(user);



    filterResults.count = tempList.size();
    filterResults.values = tempList;
    else
    filterResults.count = friendList.size();
    filterResults.values = friendList;


    return filterResults;


    /**
    * Notify about filtered list to ui
    * @param constraint text
    * @param results filtered result
    */
    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence constraint, FilterResults results)
    filteredList = (ArrayList<User>) results.values;
    notifyDataSetChanged();




    Implement Filterable to your adapter , and write the following code to your Override function getfilter.



     if (brandFilter == null) 
    Filter = new BrandFilter();


    return friendFilter;


    Just call this method inside your activity , on onQueryTextChange



     mAdapetr.getFilter().filter(newText);





    share|improve this answer













    Create a private class inside your adapter



     /**
    * Custom filter for Brand list
    * Filter content in brand list according to the search text
    */
    private class BrandFilter extends Filter

    @Override
    protected FilterResults performFiltering(CharSequence constraint)
    FilterResults filterResults = new FilterResults();
    if (constraint!=null && constraint.length()>0)
    ArrayList<User> tempList = new ArrayList<User>();

    // search content in Brand list
    for (User user : brandList)
    if (mList.getBrandName().toLowerCase().contains(constraint.toString().toLowerCase()))
    tempList.add(user);



    filterResults.count = tempList.size();
    filterResults.values = tempList;
    else
    filterResults.count = friendList.size();
    filterResults.values = friendList;


    return filterResults;


    /**
    * Notify about filtered list to ui
    * @param constraint text
    * @param results filtered result
    */
    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence constraint, FilterResults results)
    filteredList = (ArrayList<User>) results.values;
    notifyDataSetChanged();




    Implement Filterable to your adapter , and write the following code to your Override function getfilter.



     if (brandFilter == null) 
    Filter = new BrandFilter();


    return friendFilter;


    Just call this method inside your activity , on onQueryTextChange



     mAdapetr.getFilter().filter(newText);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 26 at 7:00









    Mini ChipMini Chip

    3171 silver badge6 bronze badges




    3171 silver badge6 bronze badges












    • What's the brandFilter may I ask?

      – saap mong
      Mar 26 at 7:07











    • @Override public Filter getFilter() if (brandFilter == null) Filter = new BrandFilter(); return friendFilter;

      – saap mong
      Mar 26 at 7:10











    • Hi I managed to make it work already. However, whenever i search,and then backspace the words, the listview doesnt refresh back to its original. How do I solve this?

      – saap mong
      Mar 26 at 7:48











    • you need to clear the list , and notify your adapter .

      – Mini Chip
      Mar 26 at 8:01











    • I have given the example form my code base . you can make the changes accordingly to your adapter . every time you write a query of anything , jus notify your adapter .

      – Mini Chip
      Mar 26 at 8:02

















    • What's the brandFilter may I ask?

      – saap mong
      Mar 26 at 7:07











    • @Override public Filter getFilter() if (brandFilter == null) Filter = new BrandFilter(); return friendFilter;

      – saap mong
      Mar 26 at 7:10











    • Hi I managed to make it work already. However, whenever i search,and then backspace the words, the listview doesnt refresh back to its original. How do I solve this?

      – saap mong
      Mar 26 at 7:48











    • you need to clear the list , and notify your adapter .

      – Mini Chip
      Mar 26 at 8:01











    • I have given the example form my code base . you can make the changes accordingly to your adapter . every time you write a query of anything , jus notify your adapter .

      – Mini Chip
      Mar 26 at 8:02
















    What's the brandFilter may I ask?

    – saap mong
    Mar 26 at 7:07





    What's the brandFilter may I ask?

    – saap mong
    Mar 26 at 7:07













    @Override public Filter getFilter() if (brandFilter == null) Filter = new BrandFilter(); return friendFilter;

    – saap mong
    Mar 26 at 7:10





    @Override public Filter getFilter() if (brandFilter == null) Filter = new BrandFilter(); return friendFilter;

    – saap mong
    Mar 26 at 7:10













    Hi I managed to make it work already. However, whenever i search,and then backspace the words, the listview doesnt refresh back to its original. How do I solve this?

    – saap mong
    Mar 26 at 7:48





    Hi I managed to make it work already. However, whenever i search,and then backspace the words, the listview doesnt refresh back to its original. How do I solve this?

    – saap mong
    Mar 26 at 7:48













    you need to clear the list , and notify your adapter .

    – Mini Chip
    Mar 26 at 8:01





    you need to clear the list , and notify your adapter .

    – Mini Chip
    Mar 26 at 8:01













    I have given the example form my code base . you can make the changes accordingly to your adapter . every time you write a query of anything , jus notify your adapter .

    – Mini Chip
    Mar 26 at 8:02





    I have given the example form my code base . you can make the changes accordingly to your adapter . every time you write a query of anything , jus notify your adapter .

    – Mini Chip
    Mar 26 at 8:02













    0














    For temp list :



     private ArrayList<Model> filteredList;


    and in your constructor



    this.filteredList = auctionList


    while publishing result , /**
    * Notify about filtered list to ui
    * @param constraint text
    * @param results filtered result
    */
    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence constraint, FilterResults results)
    filteredList = (ArrayList<Model>) results.values;
    notifyDataSetChanged();






    share|improve this answer



























      0














      For temp list :



       private ArrayList<Model> filteredList;


      and in your constructor



      this.filteredList = auctionList


      while publishing result , /**
      * Notify about filtered list to ui
      * @param constraint text
      * @param results filtered result
      */
      @SuppressWarnings("unchecked")
      @Override
      protected void publishResults(CharSequence constraint, FilterResults results)
      filteredList = (ArrayList<Model>) results.values;
      notifyDataSetChanged();






      share|improve this answer

























        0












        0








        0







        For temp list :



         private ArrayList<Model> filteredList;


        and in your constructor



        this.filteredList = auctionList


        while publishing result , /**
        * Notify about filtered list to ui
        * @param constraint text
        * @param results filtered result
        */
        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results)
        filteredList = (ArrayList<Model>) results.values;
        notifyDataSetChanged();






        share|improve this answer













        For temp list :



         private ArrayList<Model> filteredList;


        and in your constructor



        this.filteredList = auctionList


        while publishing result , /**
        * Notify about filtered list to ui
        * @param constraint text
        * @param results filtered result
        */
        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results)
        filteredList = (ArrayList<Model>) results.values;
        notifyDataSetChanged();







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 8:26









        Mini ChipMini Chip

        3171 silver badge6 bronze badges




        3171 silver badge6 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55351067%2fimplementing-search-function-to-search-in-listview-by-specific-textview%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript