mentions icon indicating copy to clipboard operation
mentions copied to clipboard

how to insert Multiple Mention at a time

Open knowamit opened this issue 6 years ago • 4 comments

I have a list of 5 users I want to insert them into edit text but I am not able to insert them.

                    mention.setMentionName(user.getFIRSTNAME());
                    mention.setMentionId(user.getPERSON_ID());
                   mentions.insertMention(mention);

knowamit avatar Jun 06 '18 16:06 knowamit

@amitsharma492 Did you able to resolve this issue ?

iamshajeer avatar May 28 '19 08:05 iamshajeer

@iamshajeer / @amitsharma492 did you find any solution for this issue? Experiencing the same issue here. When I try to insert using by creating mention's object it throws the stackoverflowerror.

val mention = Mention()
 mention.mentionName = tagUsers.full_name
 mention.mentionId = tagUsers.id
 mention.mentionOffset = mentionedPattern.start()
 mention.mentionLength = mentionedPattern.end() - mentionedPattern.start()
 mentions?.insertMention(mention)

DhavalsShah avatar Oct 10 '19 09:10 DhavalsShah

Still I am getting an error with insertMention() method. However, I found other way to achieve the same by adding list of mention using addMentions() method.

var commentStringBuilder = StringBuilder(comment)
if (tagUsersList != null && tagUsersList.isNotEmpty()) {
        var listOfMentions = ArrayList<Mention>()
        for (tagUsers in tagUsersList) {
                 val p = Pattern.compile("~<<<" + tagUsers.id + ">>>~")
                 val mentionedPattern = p.matcher(commentStringBuilder)

                 if (mentionedPattern.find()) {
                        val mention = Mention()
                        mention.mentionName = tagUsers.full_name
                        mention.mentionId = tagUsers.id
                        mention.mentionOffset = mentionedPattern.start()
                        mention.mentionLength = tagUsers.full_name.length
                        listOfMentions.add(mention)
                        commentStringBuilder = commentStringBuilder.replace(mentionedPattern.start(), mentionedPattern.end(), tagUsers.full_name)
                    }
                }
mentions?.addMentions(listOfMentions)

DhavalsShah avatar Oct 10 '19 13:10 DhavalsShah

Try this way 👍 It will work.

EditText editTextObject = findViewById(R.id.xx);
Mentions mentions = new Mentions.Builder(this, editTextObject)
                .suggestionsListener(this)
                .queryListener(this)
                .build();`


List<UserModel> users;
public void insertMultiple(){
for (int i = 0; i < users.size(); i++) {
 editTextObject.append("@");
 editTextObject.setSelection(editTextObject.getText().length());
 editTextObject.setCursorVisible(true);
 editTextObject.requestFocus();
 final Mention mention = new Mention();
 mention.setMentionName(users.get(i).getFIRSTNAME());
 mention.setMentionId(users.get(i).getPERSON_ID());
 mentions.insertMention(mention);
}
}

knowamit avatar Oct 14 '19 18:10 knowamit