splitwise / TokenAutoComplete

Gmail style MultiAutoCompleteTextView for Android
Apache License 2.0
1.3k stars 383 forks source link

onItemClick Not Firing #293

Closed Tobster619 closed 7 years ago

Tobster619 commented 7 years ago

I'm trying to use the below onItemClick so that when a token is clicked on, it is converted back into editable text so then the user can make a change to the email address however, this function is never called.

completionViewTo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                Log.d(TAG, "onItemClick");
                Person personObject = (Person)adapterView.getSelectedItem();
                //adapterView.getItemAtPosition(position);
                String personEmail = personObject.getEmail();
                completionViewTo.removeObject(personObject);
                completionViewTo.getText().append(personEmail);
            }
        });

Full code can be seen below:

completionViewTo = (ContactsCompletionView) findViewById(R.id.searchView);
        completionViewTo.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        completionViewTo.setThreshold(1);
        completionViewTo.setLongClickable(true);

        completionViewTo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                Log.d(TAG, "onItemClick");
                Person personObject = (Person)adapterView.getSelectedItem();
                //adapterView.getItemAtPosition(position);
                String personEmail = personObject.getEmail();
                completionViewTo.removeObject(personObject);
                completionViewTo.getText().append(personEmail);
            }
        });
        completionViewTo.setTokenListener(new TokenCompleteTextView.TokenListener<Person>() {
            @Override
            public void onTokenAdded(Person token) {
                System.out.println("Added: " + token);
                System.out.println("Added: " + token.getEmail());
                contactListTo.add(token.getEmail().trim());
            }

            @Override
            public void onTokenRemoved(Person token) {
                System.out.println("Removed: " + token);
                System.out.println("Removed: " + token.getEmail());
                contactListTo.remove(token.getEmail());
            }
        });

Therefore, how can I get the onItemClick to be called or is there another way that by clicking a token, it will allow the user to edit the email address? Also, the input type doesn't seem to work either as the email address input type / keyboard layout is never shown.

mgod commented 7 years ago

I think turning it back into text inline is going to be a bit challenging, but popping up some kind of edit field is probably reasonable. See #250 for details on how to do your own custom click event.

I believe the setOnItemClickListener for the view here only applies to items clicked from the drop down list, not the tokens.