Skip to content

Commit

Permalink
Add a new variant to setTags method to accept array of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mabbas007 committed Sep 8, 2016
1 parent 5822f62 commit 709b543
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 233 deletions.
229 changes: 0 additions & 229 deletions .idea/codeStyleSettings.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/mabbas007/myapplication/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 709b543

Please sign in to comment.