on item click listener
How can detect item click event ?
Hi, v1.3 released, you use OnTagClickListener to detect item click event.
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();
}
});
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.
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.
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.
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.
@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)
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.
I am using mTagGroup.getInputTagText() but its returning empty why?