Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Public btnclear As Button
Public btnshow As Button
Public etresult As EditText
Public etsource As EditText
Public jo As JavaObject
End Sub
Public Sub Initialize
B4XPages.GetManager.LogEvents = True
jo = Me
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
B4XPages.SetTitle(Me,"Thai word break")
etsource.Text = ""
etresult.Text = ""
End Sub
Private Sub btnshow_Click
If etsource.Text = "" Then Return
etresult.Text = jo.RunMethod("start",Array(etsource.text))
End Sub
Private Sub btnclear_Click
etsource.Text = ""
etresult.Text = ""
End Sub
#if java
import java.text.BreakIterator;
import java.util.Locale;
public String start(String source) {
Locale thaiLocale = new Locale("th");
BreakIterator boundary = BreakIterator.getWordInstance(thaiLocale);
boundary.setText(source);
StringBuffer strout = new StringBuffer();
int start = boundary.first();
for (int end = boundary.next(); end != BreakIterator.DONE; start = end, end = boundary.next()) {
strout.append(source.substring(start, end) + "-");
//strout.append(source.substring(start, end) + "\r\n");
}
return strout.toString();
}
#End If