SimpleAdapter Auto complete

1

The code below is a adapter that I use to create an autocomplete in my application.

mAdapter = new SimpleAdapter(this, mPeopleList, R.layout.custcontview ,new String[] { "Name", "Email" }, new int[] { R.id.ccontName, R.id.ccontEmail});

This autocomplete is intended to:

  • Show Name

  • Show Email

The problem is as follows. It is working perfectly, when I start typing it goes showing the options that my list has to complete correctly. But it does the search for both fields, both by name and by email, which causes duplication in the display.

Thefourthandfifthparamentro("FROM" "TO"):

new String[] { "Name", "Email" }, new int[] { R.id.ccontName, R.id.ccontEmail})

This is where the logic error is, since FROM can not only put 1 field, if I do this I have to declare only 1 TO .

What I want is to do something like the following:

mAdapter = new SimpleAdapter(this, mPeopleList, R.layout.custcontview ,new String[] { "Name"}, new int[] { R.id.ccontName, R.id.ccontEmail});

But that way it does not create Autocomplete.

What should I do to get the name (FROM) from the name and send the data to (TO) ccontName and to ccontEmail ? What solution to this problem?

    
asked by anonymous 06.11.2014 / 15:33

1 answer

0
// Boa prática usar constantes para estes valores.
final String NAME = "Name";
final String EMAIL = "Email";

mAdapter = new SimpleAdapter(this, mPeopleList, R.layout.custcontview,
        // Defina os campos que deseja utilizar no filtro.
        new String[] { NAME }, new int[] { R.id.ccontName }) {

    // Reimplemente este método para poder configurar
    // os demais campos que não fazem parte do filtro.
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = super.getView(position, convertView, parent);

        // Define os demais campos que irão aparecer na lista.
        final Map<String, String> dataSet = (Map<String, String>) getItem(position);
        String email = dataSet.get(EMAIL);
        ((TextView) v.findViewById(R.id.ccontEmail)).setText(email);

        return v;
    }
};
    
07.11.2014 / 15:40