how i use the StringTokenizer class in android?

sumit tifane

New member
Feb 10, 2017
1
0
0
Visit site
i have to tokenize the sentences in token. By giving the input from edittext field ,clicking on radiobutton of tokenization and clicking on submit button,after that the output will be generate in other edittext field. how this can be perform?
here is the code :-

String s2 = String.valueOf((EditText) findViewById(R.id.editText));
editText2 = ((TextView) findViewById(R.id.editText2));
button1 = (Button) findViewById(R.id.button1);
rg1= (RadioGroup) findViewById(R.id.radioGroup2);
button1.setOnClickListener(this);
public void onClick(View v) {
int selectedId=rg1.getCheckedRadioButtonId();
rb1=(RadioButton)findViewById(selectedId);

void OnClick(View v){
StringTokenizer s1 = new StringTokenizer(s2,"");
while (s1.hasMoreTokens()) {
}
editText2.setText((CharSequence) s2);

}
 

belodion

Co-Ambassador Team Lead
Moderator
Jun 10, 2014
39,391
255
83
Visit site
This would be best moved to the developers forum.
That was what I was thinking, except that I wasn't certain that it was about development. Since the OP hasn't responded, it's down to the two of us, and I think we're both agreed about it. Over it goes. :)
 

slash me

New member
Feb 14, 2017
3
0
0
Visit site
I have used this before for autocompletetextView in my notepad application. Example below of space tokenizer :
public class SpaceTokenizer implements Tokenizer {

public int findTokenStart(CharSequence text, int cursor) {
int i = cursor;

while (i > 0 && text.charAt(i - 1) != ' ') {
i--;
}
while (i < cursor && text.charAt(i) == ' ') {
i++;
}

return i;
}

public int findTokenEnd(CharSequence text, int cursor) {
int i = cursor;
int len = text.length();

while (i < len) {
if (text.charAt(i) == ' ') {
return i;
} else {
i++;
}
}

return len;
}
You may find similar inspiration at Android development tutorial

public CharSequence terminateToken(CharSequence text) {
int i = text.length();

while (i > 0 && text.charAt(i - 1) == ' ') {
i--;
}

if (i > 0 && text.charAt(i - 1) == ' ') {
return text;
} else {
if (text instanceof Spanned) {
SpannableString sp = new SpannableString(text + " ");
TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
Object.class, sp, 0);
return sp;
} else {
return text + " ";
}
}
}
}