diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml deleted file mode 100644 index 78eefeb..0000000 --- a/.idea/codeStyleSettings.xml +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java b/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java index 6194ea3..5f8fb01 100644 --- a/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java +++ b/TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java @@ -196,6 +196,30 @@ public void setTags(CharSequence... tags) { mTextWatcher.afterTextChanged(getText()); } + /** + * use this method to set tags + */ + + public void setTags(String[] tags) { + mTagSpans.clear(); + mTags.clear(); + + int length = tags != null ? tags.length : 0; + int position = 0; + for (int i = 0; i < length; i++) { + Tag tag = new Tag(); + tag.setIndex(i); + tag.setPosition(position); + String source = mIsSpacesAllowedInTags ? tags[i].trim() : tags[i].replaceAll(" ", ""); + tag.setSource(source); + tag.setSpan(true); + mTags.add(tag); + position += source.length() + 1; + } + buildStringWithTags(mTags); + mTextWatcher.afterTextChanged(getText()); + } + @Override public Parcelable onSaveInstanceState() { diff --git a/app/src/main/java/mabbas007/myapplication/MainActivity.java b/app/src/main/java/mabbas007/myapplication/MainActivity.java index b411571..0b371c9 100644 --- a/app/src/main/java/mabbas007/myapplication/MainActivity.java +++ b/app/src/main/java/mabbas007/myapplication/MainActivity.java @@ -7,10 +7,8 @@ import android.view.View; import android.widget.ArrayAdapter; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.List; import mabbas007.tagsedittext.TagsEditText; @@ -53,7 +51,8 @@ public void onWindowFocusChanged(boolean hasFocus) { public void onClick(View v) { switch (v.getId()) { case R.id.btnChangeTags: { - mTagsEditText.setTags("1", "2", "3"); + //mTagsEditText.setTags("1", "2", "3"); + mTagsEditText.setTags(new String[]{"1","2","3","4"}); break; } case R.id.btnChangeBackground: { diff --git a/build.gradle b/build.gradle index 03bced9..aff4f41 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:2.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files