FlexMobileProject, setStyle("textFormat",number) in textArea doesn't work - android

I create dynamic TextArea in Flex, I want to change its fontSize dynmically, but setStyle doesn't work.
This is my code:
var textArea:TextArea = new TextArea();
textArea.id = "txtCreaTaskAnalysis" +contatoreNumeroTextAreaCreaTaskAnalysis;
textArea.left = 140;
textArea.right = 45;
textArea.horizontalCenter = 47;
textArea.height = 110;
textArea.y = posizioneYTextArea;
var tfor:TextFormat = new TextFormat();
tfor.size= 25 ;
textArea.setStyle("textFormat",tfor);
textArea.text = tfor.size.toString();
addElement(textArea);
I have this code in a buttonClickHandler, but the fontSize doesn't change.
Help, please..

Try using :
textArea.setStyle("fontSize",25);
I don't think TextArea has a style called "textFormat".

Related

How to loop through xml resource to set ID programatically

Does somebody here have experienced how to loop through xml resource file to get ID from there and set it to view Programmaticaly.
i have already tried to research but nothing seems close to my problem
private fun createImageView(){
newView = ImageView(this)
coordinatorLayout.addView(newView)
newView.id = NewViewAssignedID //This is how i set up ID rightnow
newView.layoutParams.height = 400
newView.layoutParams.width = 400
newView.x = 520F
newView.y = 100F
newView.setImageResource(getResources().
getIdentifier(ImageToUse,"drawable","com.example.tema"))
newView.setOnTouchListener(listener)
btn_ScaleOk.isVisible = true
mScaleGestureDetector = ScaleGestureDetector(this, ScaleListener())
CanScaleNow = true
NewViewAssignedID++
Toast.makeText(this,newView.id.toString(),Toast.LENGTH_SHORT).show()
}
Need help

How can I add object to the page dynamically?

I try to add my objects to the Page1 dynamically. I know how I can create them but the problem is adding them to the page.
Here is my code sample:
var createButton = new SMF.UI.Image();
createButton.image = "answer.png";
createButton.top = 5;
createButton.width = 38;
createButton.height = 38;
createButton.left = 5;
createButton.imageFillType = SMF.UI.ImageFillType.aspectFit;
createButton.onShow = function(e) {
alert("object created");
};
It is very simple. Like other programming language just use add method. You have to give a parameter which is your obect. Take a look below.
Pages.Page1.add(createButton);

How to set maxlength for edit text programmatically? [duplicate]

I would like to programmatically set maxLength property of TextView as I don't want to hard code it in the layout. I can't see any set method related to maxLength.
Can anyone guide me how to achieve this?
Should be something like that. but never used it for textview, only edittext :
TextView tv = new TextView(this);
int maxLength = 10;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
tv.setFilters(fArray);
Try this
int maxLengthofEditText = 4;
editText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLengthofEditText)});
For those of you using Kotlin
fun EditText.limitLength(maxLength: Int) {
filters = arrayOf(InputFilter.LengthFilter(maxLength))
}
Then you can just use a simple editText.limitLength(10)
Easy way limit edit text character :
EditText ed=(EditText)findViewById(R.id.edittxt);
ed.setFilters(new InputFilter[]{new InputFilter.LengthFilter(15)});
As João Carlos said, in Kotlin use:
editText.filters += InputFilter.LengthFilter(10)
See also https://stackoverflow.com/a/58372842/2914140 about some devices strange behaviour.
(Add android:inputType="textNoSuggestions" to your EditText.)
For Kotlin and without resetting previous filters:
fun TextView.addFilter(filter: InputFilter) {
filters = if (filters.isNullOrEmpty()) {
arrayOf(filter)
} else {
filters.toMutableList()
.apply {
removeAll { it.javaClass == filter.javaClass }
add(filter)
}
.toTypedArray()
}
}
textView.addFilter(InputFilter.LengthFilter(10))
I made a simple extension function for this one
/**
* maxLength extension function makes a filter that
* will constrain edits not to make the length of the text
* greater than the specified length.
*
* #param max
*/
fun EditText.maxLength(max: Int){
this.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(max))
}
editText?.maxLength(10)
My solution for SWIFT 5
editText.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(123))
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title");
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
//for Limit...
input.setFilters(new InputFilter[] {new InputFilter.LengthFilter(3)});
builder.setView(input);
best solution i found
textView.setText(text.substring(0,10));
To keep the original input filter, you can do it this way:
InputFilter.LengthFilter maxLengthFilter = new InputFilter.LengthFilter(100);
InputFilter[] origin = contentEt.getFilters();
InputFilter[] newFilters;
if (origin != null && origin.length > 0) {
newFilters = new InputFilter[origin.length + 1];
System.arraycopy(origin, 0, newFilters, 0, origin.length);
newFilters[origin.length] = maxLengthFilter;
} else {
newFilters = new InputFilter[]{maxLengthFilter};
}
contentEt.setFilters(newFilters);

as3 StageText cursor does not show up

here is the code that creates the StageText
var myTextField:StageText = new StageText();
myTextField.returnKeyLabel = ReturnKeyLabel.SEARCH;
myTextField.text = tlf.text;
myTextField.editable = true;
myTextField.fontFamily = "Ariel"
myTextField.fontSize = 40;
myTextField.color = tlf.textColor
myTextField.textAlign = TextFormatAlign.RIGHT
myTextField.stage = stage;
myTextField.viewPort = new Rectangle(p.x, p.y, tlf.width*screenUtil.xScaleFactor,tlf.height*screenUtil.yScaleFactor);
txtInputVo.stageText = myTextField;
myTextField.locale = "he-IL";
myTextField.addEventListener(FocusEvent.FOCUS_IN, onInFocus);
myTextField.addEventListener(FocusEvent.FOCUS_OUT, onOutFocus);
protected function onInFocus(event:FocusEvent):void
{
var sTxt:StageText = event.currentTarget as StageText;
var textInputVo:TextInputVO = getTextInputVO(sTxt);
if(textInputVo.defultText == sTxt.text)
{
sTxt.text = "";
}
}
It's working great, the keybord is showing up and you can insert and edit the text
but the cursor is not showing up?
I have only tested it on the Android Air 3.6 so far.
Try "Arial" not "Ariel" as font family

How to programmatically set maxLength in Android TextView?

I would like to programmatically set maxLength property of TextView as I don't want to hard code it in the layout. I can't see any set method related to maxLength.
Can anyone guide me how to achieve this?
Should be something like that. but never used it for textview, only edittext :
TextView tv = new TextView(this);
int maxLength = 10;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
tv.setFilters(fArray);
Try this
int maxLengthofEditText = 4;
editText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLengthofEditText)});
For those of you using Kotlin
fun EditText.limitLength(maxLength: Int) {
filters = arrayOf(InputFilter.LengthFilter(maxLength))
}
Then you can just use a simple editText.limitLength(10)
Easy way limit edit text character :
EditText ed=(EditText)findViewById(R.id.edittxt);
ed.setFilters(new InputFilter[]{new InputFilter.LengthFilter(15)});
As João Carlos said, in Kotlin use:
editText.filters += InputFilter.LengthFilter(10)
See also https://stackoverflow.com/a/58372842/2914140 about some devices strange behaviour.
(Add android:inputType="textNoSuggestions" to your EditText.)
For Kotlin and without resetting previous filters:
fun TextView.addFilter(filter: InputFilter) {
filters = if (filters.isNullOrEmpty()) {
arrayOf(filter)
} else {
filters.toMutableList()
.apply {
removeAll { it.javaClass == filter.javaClass }
add(filter)
}
.toTypedArray()
}
}
textView.addFilter(InputFilter.LengthFilter(10))
I made a simple extension function for this one
/**
* maxLength extension function makes a filter that
* will constrain edits not to make the length of the text
* greater than the specified length.
*
* #param max
*/
fun EditText.maxLength(max: Int){
this.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(max))
}
editText?.maxLength(10)
My solution for SWIFT 5
editText.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(123))
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title");
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
//for Limit...
input.setFilters(new InputFilter[] {new InputFilter.LengthFilter(3)});
builder.setView(input);
best solution i found
textView.setText(text.substring(0,10));
To keep the original input filter, you can do it this way:
InputFilter.LengthFilter maxLengthFilter = new InputFilter.LengthFilter(100);
InputFilter[] origin = contentEt.getFilters();
InputFilter[] newFilters;
if (origin != null && origin.length > 0) {
newFilters = new InputFilter[origin.length + 1];
System.arraycopy(origin, 0, newFilters, 0, origin.length);
newFilters[origin.length] = maxLengthFilter;
} else {
newFilters = new InputFilter[]{maxLengthFilter};
}
contentEt.setFilters(newFilters);

Categories

Resources