0

In my fragment class having customized listview.I have also one edit text in it to filter list records on text changed. but some how i am unable to implement it in fragmnet

here is my code :
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
{
    View view = inflater.inflate(R.layout.activity_main, null);

    llMain = (LinearLayout) view.findViewById(R.id.llMain); 
    llMain.setBackgroundColor(Color.GRAY);

    InputSearch=(EditText)view.findViewById(R.id.search);
    InputSearch.addTextChangedListener(new TextWatcher() 
    {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s);// Error on this line: create method getFilter() in customadapter

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s)
 {
            // TODO Auto-generated method stub

        }
    });
}
User_B
  • 17
  • 1
  • 4

2 Answers2

1

Change lineadapter.getFilter().filter(s); to MyActivity.this.adapter.getFilter().filter(s);

Karan Maru
  • 991
  • 6
  • 17
  • adapter is object of my CustomAdpater class which extends BaseAdapter. so in this case what to do – User_B Jan 21 '15 at 05:42
  • Have you implement Filterable interface in yorr adapter class? Please go through this link : http://codetheory.in/android-filters/ ; http://www.survivingwithandroid.com/2012/10/android-listview-custom-filter-and.html – Karan Maru Jan 21 '15 at 05:42
  • its working but now problem is that when i type one letter suppose it is 'a' then all name gets display on the list which contains letter 'a' – User_B Jan 21 '15 at 10:25
  • Then it's a solution :-) – Karan Maru Jan 21 '15 at 12:39
  • yes its working but i want only those names which starts from the letter i typed .it displays all names which contains 'a'. like if i typed 'anj' then i only want to display name starts from 'anj' instead of 'xyzanj'. – User_B Jan 22 '15 at 06:24
0

you have to implement Filterable for CustomAdapter and ovverride getFilter() method.

public CustomAdapter extends BaseAdapter implements Filterable 
{
     //override all adapter methods

     @Override
    public Filter getFilter() {

        // your code here
        return null;
    }
}
Amey Haldankar
  • 2,223
  • 1
  • 24
  • 22
  • @User_B Use this http://stackoverflow.com/questions/25631382/filtering-list-of-apps-in-custom-baseadapter , http://stackoverflow.com/questions/24769257/custom-listview-adapter-with-filter-android – Piyush Jan 21 '15 at 07:37