How to use android native code in nativescript


#1

I want to use Right-To-Left scroll view.
In android with java we wrote this two line code:

hor = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
hor.fullScroll(HorizontalScrollView.FOCUS_RIGHT);

How can I do it in nativescript? or better question is how can I access Focus_RIGHT in nativescript?


#2

You should be able to access it by adding the package. Try console.log("focus right: " + android.widget.HorizontalScrollView.FOCUS_RIGHT)


#3

Since HorizontalScrollView can be absolutely anything in JavaScript, you’d need to specify the full package name for the class whose public members, static or not, you are accessing.

To access a NativeScript view’s underlying android component you can look for the view’s android property.

let scrollview = topmost.getViewById("myScrollView");
scrollview.android.fullScroll(android.widget.HorizontalScrollView.FOCUS_RIGHT);

alternatively you can save the package in a variable, for Java-like access to classes:

let HorizontalScrollView = android.widget.HorizontalScrollView;