AndroidTagGroup icon indicating copy to clipboard operation
AndroidTagGroup copied to clipboard

on item click listener

Open aclgn opened this issue 10 years ago • 9 comments

How can detect item click event ?

aclgn avatar May 17 '15 10:05 aclgn

Hi, v1.3 released, you use OnTagClickListener to detect item click event.

2dxgujun avatar May 23 '15 02:05 2dxgujun

Hello, I tried that method, but it doesn't giving callback.

Code:

mTagGroup = (TagGroup) findViewById(R.id.tag_group); mTagGroup.setTags(new String[]{"Tag1", "Tag2" });

    mTagGroup.setOnTagClickListener(new TagGroup.OnTagClickListener() {
        @Override
        public void onTagClick(String s) {


            Toast.makeText(getApplicationContext(), "Tag clicked",
                    Toast.LENGTH_LONG).show();
        }
    });

viii2050 avatar May 25 '15 12:05 viii2050

Hi The demo app works fine on my Nexus5(Android 4.4). Please check if you dependency is latest, and you can install the demo app to check if it works fine on your phone.

2dxgujun avatar May 25 '15 12:05 2dxgujun

Thanks for the quick response. Yes, i am using latest dependency, working on Nexus7(Lollipop 5.0.1). I want the listener only to detect space key is pressed while typing new tag, so i can submit the tag on space key click.

I also tried below code but not giving any callback.


private TagGroup.OnKeyListener mOnKeyListener = new TagGroup.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) {

        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                (keyCode == KeyEvent.KEYCODE_ENTER)) {
            // Perform action on key press
            Toast.makeText(getApplicationContext(), "enter key pressed", Toast.LENGTH_SHORT).show();
            return true;
        }
        return false;
    }
};

Also i am unable to restrict the multiline for tag , as whenever i click 'enter' cursor goes to next line. Waiting for your response.

Thanks in advance.

viii2050 avatar May 25 '15 13:05 viii2050

Space key? But your code use KeyEvent.KEYCODE_ENTER...

TagGroup is only a container for tags, so it can't detect any key events.

The library is originally support the 'ENTER' key to submit a new tag, except the Google Soft Keyboard, because the Google Soft Keyboard doesn't propagate the key events for the software key strokes, see Issus 1.

As a workaround, you can tap the tag group blank area for submit a new tag, or use submitTag().

Update: OnKeyListener java doc:

Interface definition for a callback to be invoked when a hardware key event is dispatched to this view. The callback will be invoked before the key event is given to the view. This is only useful for hardware keyboards; a software input method has no obligation to trigger this listener.

2dxgujun avatar May 25 '15 14:05 2dxgujun

Sorry i wanted to ask for "enter" key only. I got what you mean to say.

The only concern is i want to restrict tag in single line, e.g. as we use android:singleLine="true" for edittext

is this possible?

In short i don't want 'enter key' press goes to next line in Google Soft Keyboard.

viii2050 avatar May 25 '15 14:05 viii2050

@2dxgujun can you please tell me, is it technically possible?

Also can you please tell, is there any way we can limit the number of tags created? (e.g. i want to show warning if user tries to create more than 10 tags)

viii2050 avatar Jun 02 '15 13:06 viii2050

I'm sorry, i got some exam lately.

I have make some test today.The Google keyboard always crash :( and the Chinese keyboard which i always use suddenly not propagate the key events ('enter key' press goes to next line)......This got to be kidding me!

I call setSingleLine(), and fix the canvas issue.

Yes, the tag restrict in single line, but the 'enter key' just close the keyboard instead of 'end input' then append the new input tag.


Yes, there is a way we can get the number of tags created.

Set callback interface OnTagChangeListener, get the number of tags like that:

mTagGroup.setOnTagChangeListener(new TagGroup.OnTagChangeListener() {
    @Override
    public void onAppend(TagGroup tagGroup, String tag) {
        int length = tagGroup.getTags().length;
        Log.d(TAG, "Tag count: " + length);
    }

    @Override
    public void onDelete(TagGroup tagGroup, String tag) {
        int length = tagGroup.getTags().length;
        Log.d(TAG, "Tag count: " + length);
    }
});

Thank you for feed back.

2dxgujun avatar Jun 03 '15 12:06 2dxgujun

I am using mTagGroup.getInputTagText() but its returning empty why?

Ayaz12 avatar Dec 18 '15 13:12 Ayaz12