selecting contact from autocomplete textview

后端 未结 3 677
情话喂你
情话喂你 2020-12-01 05:00

i want to select the contact using autocomplete textview for sending sms. I have almost achieved what i want, but for one minute problem as you can see in the image. How can

相关标签:
3条回答
  • 2020-12-01 05:13

    The output you currently have seems to be the standard output of HashMap.toString method. So, you should make your own implementation of HashMap and override toString method.

    0 讨论(0)
  • 2020-12-01 05:15

    Add a onItemClickListener for the AutoCompleteTextView instead of having it as a seperate function.

     mTxtPhoneNo.setOnItemClickListener(new OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView<?> av, View arg1, int index,
                    long arg3) {
                Map<String, String> map = (Map<String, String>) av.getItemAtPosition(index);
    
                String name  = map.get("Name");
                String number = map.get("Phone");
                mTxtPhoneNo.setText(""+name+"<"+number+">");
    
            }
    
    
    
        });
    

    or implement OnItemClickListener for your activity and set

    mTxtPhoneNo.setOnItemClickListener(this);
    
    0 讨论(0)
  • 2020-12-01 05:26

    With an AutoCompeleteTextView its can be useful just to do as what @user936414 said, but it can makes problem if you have biggest app, even more with an multiAutoCompeleteTextView so it s recommended to overide toString methode by creating a "custom" HashMap like that :

    public class ContactMap extends HashMap<String, String> {
    
    /*
     * (non-Javadoc)
     * 
     * @see java.util.AbstractMap#toString()
     */
    @Override
    public String toString() {
        if (isEmpty()) {
            return "{}";
        }
    
        StringBuilder buffer = new StringBuilder(size() * 28);
        Iterator<Map.Entry<String, String>> it = entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> entry = it.next();
            Object key = entry.getKey();
    
            if (key == "Name") {
                Object value = entry.getValue();
                buffer.append(value);
            } else {
                if (key == "Phone")
                    buffer.append("<");
                Object value = entry.getValue();
                if (value != this) {
                    buffer.append(value);
                } else {
                    buffer.append("(this Map)");
                }
                if (key == "Phone")
                    buffer.append(">");
    
            }
        }
    
        return buffer.toString();
    }
    
    }
    

    and use it like this

                        // Using our custom HashMap
                        ContactMap NamePhoneType = new ContactMap();
    
    0 讨论(0)
提交回复
热议问题