[Android] How to create text widget object

Hi everyone,

in the samples I only see this:

android:layout_height="fill_parent" />

but I want to create an object of SingleCharWidgetApi and then add it to a layout from code.
How can I do that?

Thanks for your message.
Did you try to run the single char sample? You should have a look to the 'MainActivity.java' content, it may help, especially the following method:

 protected void onCreate(Bundle savedInstanceState) {


mResourceHelper = new SimpleResourceHelper(this);
mLanguageManager = new LanguageManager(this);

mBtLayout = (LinearLayout) findViewById(R.id.btn_layout);

mAppView = (RelativeLayout) findViewById(R.id.app_view);
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) mAppView.getLayoutParams();
lp.width = lp.height = getPreferences(MODE_PRIVATE).getInt(KEY_VIEW_SIZE, Math.round(getResources().getDimension(R.dimen.app_size)));

mWidget = (SingleCharWidget) findViewById(R.id.widget);

mField = (FieldView) findViewById(R.id.field);


if (savedInstanceState != null) {
ArrayList<String> texts = savedInstanceState.getStringArrayList("texts");
if (texts != null) {


// Uncomment the following lines to configure ink marker effect

// mWidget.setInkCapResources(R.drawable.ink_cap, R.drawable.ink_cap);
// mWidget.setInkEffect(SingleCharWidget.INK_EFFECT_MARKER);

setTitle(getResources().getString(R.string.app_name) + " " + com.myscript.atk.scw.Build.VERSION.RELEASE);

mSpaceButton = (Button) findViewById(R.id.btn_space);
final GestureDetector mSpaceDetector;
mSpaceDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

Please let us know if you need more details.
Best regards

Thank you for your reply but I think you misunderstood me. :/

In the code you posted, there is the line mWidget = (SingleCharWidget) findViewById(R.id.widget);. This gets the widget from the layout, not creating an object with new SingleCharWidget from code.
Why is the class here called SingleCharWidget and in the docs SingleCharWidgetApi by the way?

Sorry for the misunderstanding, the SingleCharWidgetApi includes methods that you can call once an instance of the singlechar widget has been created (Please refer to the API documentation)
From the layout point of view, no api item has to be created actually. The sample shows UI elements to create: for instance, writing areas to capture the digital ink, then the SingleCharWidget object and methods of the API allows to process this ink.
Could you please give us more details about the use case you want to implement? It may help to better understand your needs and answer your questions.
Best regards

I want to implement your widgets into Xamarin.Forms and I need to write a CustomRenderer for that (http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/)
Inside of it I need to pass the widget to the renderer, so I need to create something thats an Android View.

Unfortunately regarding the Xamarin environment, we do not support it, and do not even know if the MyScript ATK can run on it. Indeed, due to the multiple environments that exist, it is not possible to try all of these, which is why we decided to focus on the Eclipse environment on Android.
Please accept our apologies for this limitation.
Best regards

The only thing I wanted to know was how to make an object from code (eg. SingleCharWidget widget = new SingleCharWidget()) and NOT getting it from the layout (like in your example). I don't need assistance in implementing it in Xamarin, you would help me a great deal with just answering if it is possible to make an object from purely code.

I am sorry but it is not possible.
Best regards.

Login or Signup to post a comment