how i use the StringTokenizer class in android?

sumit tifane

New member
Feb 10, 2017
1
0
0
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);

}
 
Welcome. :)

Is this something to do with app development?
 
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. :)
 
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 + " ";
}
}
}
}
 

Trending Posts

Members online

Forum statistics

Threads
954,623
Messages
6,962,227
Members
3,163,093
Latest member
raojames