Simpleadapter Auto complete

Asked

Viewed 46 times

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 aims to:

  • Mostar Nome

  • Show Email

Okay, here’s the problem. It is working perfectly, when I start typing it will show the options that my list has to complete correctly. But it does the search for the two fields, both by name and by email, which generates a duplicity in the display.

The fourth and fifth parameter ("FROM" "TO") :

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

That’s where the logic error lies, because the FROM I cannot put only 1 field, if I do this I have to declare only 1 TO.

What I want is to do something like this:

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

Only that way it doesn’t create Autocomplete.

What should I do to make him search (FROM) by name and send the data to (TO) ccontName and for ccontEmail? What solution to this problem?

  • I don’t work with Java but it seems that everything is well explained, I just edited the formatting and spelling problems. I was left with doubt at the time of edit ccontName EEEE para ccontEmail, I believe I simply wanted to emphasize and; that’s it?

  • Yeah, it looked like hexadecimal code :p

  • checks before displaying on Toast

  • How can I do this ? Sorry, this is the first time I’m working with this feature

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;
    }
};
  • PERFECT!! Thank you so much for your help !!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.