0
  1. The user types 2 letters in the autocomplete text box
  2. Those 2 letters get saved and used in a web service method in order to retrieve all users who start with those 2 letters
  3. XML result get returned, and get parsed, and we retrieve the user name+ the id and save each one in different ArrayList
  4. the result from the first name arraylist get puts in an a dropdown list (the autocomplete one)
  5. The user select an item from the drop list items

-- I need to display the name in the drop down list, however, when the user chooses a name, that user ID should be selected and saved as a String in order to be used for another query.

Question is: How to display the name but select the ID for that name

    AutoCompleteTextView assigneeInput;
    assigneeInput=(AutoCompleteTextView)

    findViewById(id.editassignee);

    assigneeInput.addTextChangedListener(new

    TextWatcher() {

        @Override
        public void onTextChanged (CharSequence s,int start, int before, int count){
            getContactsForAssignee();
        }
        @Override
        public void beforeTextChanged (CharSequence s,int start, int count, int after){
        }
        @Override
        public void afterTextChanged (Editable s){
        }
    }

    );
    //Textwatcher for assignee input -end

}

    //Method to get Contacts for the assignee autocomplete - Start
    public void getContactsForAssignee() {
        //webservice call method

    }
//Method to get Contacts for the assignee autocomplete - End

    public void receiveResults10(String result10) {

        try {

            //Dom parsing set up

            List<String> valSetOne = new ArrayList<String>();
            List<String> valSetTwo = new ArrayList<String>();
            ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();


            for (int i = 0; i < nodesUDSObjectList.getLength(); i++) {
                Element elementUDSObject = (Element) nodesUDSObjectList.item(i);
                NodeList nodesAttributeList = elementUDSObject.getElementsByTagName("Attribute");

                HashMap<String, String> mapp = new HashMap<String, String>();


                for (int iA = 0; iA < nodesAttributeList.getLength(); iA++) {
                    Element elementAttribute = (Element) nodesAttributeList.item(iA);
                    //You have attribute(iA)


                    NodeList AttrNameElementList = (NodeList) elementAttribute.getElementsByTagName("AttrName");
                    String nameValue = getCharacterDataFromElement((Element) (AttrNameElementList.item(0)));

                    System.out.println("name" + nameValue);

                    NodeList AttrValueElementList = (NodeList) elementAttribute.getElementsByTagName("AttrValue");
                    String valueValue = getCharacterDataFromElement((Element) (AttrValueElementList.item(0)));

                    if (nameValue.equals("name")) {
                        valSetOne.add(valueValue);
                        mapp.put(COMBO_NAME, valueValue);
                    }
                    if (nameValue.equals("id")) {
                        valSetTwo.add(valueValue);
                        mapp.put(PERSISTENT_ID, valueValue);
                    }
                }
                menuItems.add(mapp);
            }
            AutoCompleteTextView editAssignee;
            ArrayAdapter<String> adapter;

            adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, valSetOne);
            editAssignee = (AutoCompleteTextView) findViewById(R.id.editassignee);
            editAssignee.setAdapter(adapter);

        } catch (Exception e) {

            e.printStackTrace();


        }

    }

    public static String getCharacterDataFromElement(Element e) {

    }

    //Beginning of method to actually save the ticket executed on click of the "save" button
    public void SaveThisIncident(View v) {
        AutoCompleteTextView editAssigneeInput = (AutoCompleteTextView) findViewById(R.id.editassignee); //receiving the users input for assignee
        String thisIsAssignee = editAssigneeInput.getText().toString();
    }
Mash
  • 174
  • 1
  • 1
  • 10

1 Answers1

0

You need to set itemclicklistner for your AutoCompleteTextView editAssignee & use BaseAdapter instead of ArrayAdapter.

Pass ArrayList of your custom object which contain both id & string value to baseadapter.

Custom object can be

public class item{
String id;
String value;
}

Now onClickItem you can get both id & value from your Arraylist

Akhil
  • 6,495
  • 3
  • 27
  • 59
  • how can I do that, do you mind showing me how? much appreciated – Mash Sep 19 '14 at 05:54
  • if i changed ArrayAdapter to BaseAdapter i get errors"The type BaseAdapter is not generic; it cannot be parameterized with arguments " if you know how to solve my issue plzzz help me, i really need it to work urgently – Mash Sep 19 '14 at 07:54
  • You can refer this answer for Baseadapter usage http://stackoverflow.com/a/16335923/1677824 – Akhil Sep 19 '14 at 12:44