0

1) The code below : getView does not get called when I type in autocompletetextview. Watch out the list in the fragment and the adapter class extending List

   public class SigninFragment extends Fragment {
        private List<Test> list= null;

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Test tes= new Test ();
    tes.setId(1);
    tes.setDesc("descabc");
    list= new ArrayList<>();
    list.add(prof);

    tesListAdapter =
            new TesListAdapter(
                    rootView.getContext()
                    ,R.layout.list_row_adapter
                    ,list);

    autocompletetextview.setThreshold(3);
    autocompletetextview.setAdapter(tesListAdapter );

My Adapter Class :

public class ProfissoesListAdapter extends ArrayAdapter<Test> { **<==HERE**
    private LayoutInflater inflater;
    private int resource;

public TesListAdapter(Context activity, int resource, List<Test> listaProf) **<==HERE**{

    super(activity, resource, listaProf);
    this.inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.resource = resource;
}

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

...

2) The code below : YES... getView() does get called when I type in autocompletetextview. watch out in the fragment the String[] array and the adapter exteding ArrayAdapter

   public class SigninFragment extends Fragment {
        private List<Test> list= null;

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);


    String[] list =  {"abcde","bbbbbb","bbbakaka","ccccccc","dddddd"};

    tesListAdapter =
            new TesListAdapter(
                    rootView.getContext()
                    ,R.layout.list_row_adapter
                    ,list);

    autocompletetextview.setThreshold(3);
    autocompletetextview.setAdapter(tesListAdapter );

My Adapter Class :

public class ProfissoesListAdapter extends ArrayAdapter<String> {  **<==HERE**
    private LayoutInflater inflater;
    private int resource;

public TesListAdapter(Context activity, int resource, String[] listaProf) {  **<==HERE**

    super(activity, resource, listaProf);
    this.inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.resource = resource;
}

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

...

QUESTION: Why the 1) option does not call my getView in the adapter class when I type matching value in the autocomplete textview ? thx

4
  • thats it. I have fixed this days ago and you are right. please respond it outside this comment box so I can check your answer. thx Commented Sep 22, 2015 at 17:00
  • This wasn't the reason for the comment on the other question? Commented Sep 22, 2015 at 17:04
  • nop. in the other question I have a fragment class and a custom adapter. When I debugg the adapter , its not able to find the nested elements inside RelativeLayout Commented Sep 22, 2015 at 17:13
  • @Luksprog would you please see my question if possible stackoverflow.com/questions/32722886/… Commented Sep 22, 2015 at 17:14

1 Answer 1

1

In the first case getView() doesn't get called because it doesn't match what you type in the autocomplete widget. The problem is that, when used with a custom class(not String/CharSequence), ArrayAdapter gets the data by calling toString() on the data object(in your case the Test's toString() method).

If you haven't overridden that method to return something meaningful(like the value set with setDesc()) it will return something like this Test@(somenumbershere) which will not match what you type as a filter. So, the key is to provide a proper toString() method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.