Android Question Implement inline java code

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello my friends,
I try to implement this code but with no luck.
Java Code:
B4X:
public  void makeTextViewResizable(final TextView tv, final int maxLine, final String expandText) {

        if (tv.getTag() == null) {
            tv.setTag(tv.getText());
        }
        ViewTreeObserver vto = tv.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @SuppressWarnings("deprecation")
            @Override
            public void onGlobalLayout() {

                ViewTreeObserver obs = tv.getViewTreeObserver();
                obs.removeGlobalOnLayoutListener(this);
                if (maxLine <= 0) {
                    int lineEndIndex = tv.getLayout().getLineEnd(0);
                    String text = tv.getText().subSequence(0, lineEndIndex - expandText.length() + 1) + " " + expandText;
                    tv.setText(text);
                } else if (tv.getLineCount() >= maxLine) {
                    int lineEndIndex = tv.getLayout().getLineEnd(maxLine - 1);
                    String text = tv.getText().subSequence(0, lineEndIndex - expandText.length() + 1) + " " + expandText;
                    tv.setText(text);
                }
            }
        });

    }

B4A code:
B4X:
Private nativeMe As JavaObject
nativeMe = Me
nativeMe.RunMethod("makeTextViewResizable", Array As Object(lblNotification,1,"Read more..."))

p.s. I am not very interested in be clickable and expandable. I just want to set how many lines will be for ellipsize and the text at the end of line "..."
 

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hello my friends,
p.s. I am not very interested in be clickable and expandable. I just want to set how many lines will be for ellipsize and the text at the end of line "..."

You can achieve this by using this code:

B4X:
Private jobj As JavaObject
Private lblTest As Label
'
'
jobj = lblTest
jobj.RunMethod("setLines", Array As Object(2))
jobj.RunMethod("setEllipsize", Array As Object("END"))

Based on this: https://www.b4x.com/android/forum/threads/label-utils.39338/#content
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…