mohsen programmer
Member
Hi,
I have placed the following code inside a code module:
In line 42 (where I put ##### and the click event is the text view) I want to callSub and have a sub called on a page (I'm using B4XPages).
How do I implement this?
I have placed the following code inside a code module:
B4X:
#If java
import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.Spannable;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.text.method.LinkMovementMethod;
import android.text.TextPaint;
public static void makeTextViewClickable(String EventName, TextView textView, int color, String metaChar) {
String text = textView.getText().toString();
if (text.contains("$")) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(textView.getText());
int startIndex = text.indexOf(metaChar) + 1;
int endIndex = text.indexOf(metaChar, startIndex);
String extractedText = text.substring(startIndex, endIndex);
int start = textView.getText().toString().indexOf(extractedText);
int end = start + extractedText.length();
ClickableSpan clickSpan = new ClickableSpan() {
@Override
public void updateDrawState(TextPaint ds) {
ds.setUnderlineText(false); // this remove the underline
}
@Override
public void onClick(View textView) {
try {
#####
} catch (Exception e) {
}
}
};
spannableStringBuilder.setSpan(clickSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableStringBuilder.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int index = spannableStringBuilder.toString().indexOf("$");
while (index >= 0) {
spannableStringBuilder.replace(index, index + 1, "");
index = spannableStringBuilder.toString().indexOf("$", index);
}
textView.setText(spannableStringBuilder);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);
}
}
#End If
How do I implement this?