How to lay a button right after the ellipsis in text view? - uitextview

I have a textview which has been already truncated by this:
self.textView.textContainer.maximumNumberOfLines = 2;
self.textView.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
Now, I wanna lay a button right after the ellipsis, so I can expand it at my own, but I dont have any idea how to do it. Could you suggest me some solutions?
Thanks.

Related

New to Coding Very confused

I'm new to coding in general and I'm trying to make a sprite change texture so it has a walking animation but I can't seem to figure out how to apply a wait() or something to my code.
if Input.is_action_pressed("move_up"):
vel.y -= 1
facingDir = Vector2(0, -1)
$LilBoiTexture.texture = load("res://LilBoiAssets/LilBoiBackward.png")
$LilBoiTexture.texture = load("res://LilBoiAssets/LilBoiBackward2.png")
Any help is appreciated. I'm trying to change from the first texture to the second one within idk 0.5, or something ill mess with it if i can figure out what to do.
There is an easier way of doing this instead of changing sprite image manually. You can use "AnimatedSprite" node as shown in the tutorial. Here are the steps:
1- Add an AnimatedSprite node to your character.
2- In properties of AnimatedSprite, Frames-> select new SpriteFrames.
3- Click SpriteFrames you just created, another menu will appear at the bottom of editor. Drag and drop your animation images to center of this menu.
4- Change animation name from default to something else (for example walkback).
5- In your code you just need to do this:
if Input.is_action_pressed("move_up"):
$AnimatedSprite.play("walkback")
else:
# you can also play an idle animation if you have one
$AnimatedSprite.stop()

Cursor already in the TextField when the view is changed

I'm new on Swift and I have a question.
Introduction:
View1-> a view with a button that when clicked goes to view2
View2-> a view with a text field
When I go to View2,to start writing I have to click in the text field. I want that when I change the view1 to view2, the cursor is already in text field ready to write with the keyboard up.
So do you guys no how i can do it?
Thanks for the help!
Try putting in second view controller under viewdidload function the below code
textfield.textAlignment = .left
for the keyboard
textfield.becomeFirstResponder()
Try looking at this answer
or you can follow this tutorial

I don't want to change color of JButton when pressed

Color newColor = new Color(197,222,90);
JButton newButton;
newButton = new JButton(icon);
newButton.setBacgroundColor(newColor);
When it is pressed it changes color. How can I keep it from changing color? I have multiple buttons, so if there is solution in one or two rows please help me, and keep in mind that I'm beginner, writing some huge classes won't help me, because I have multiple buttons with different names to be affected with this.
EDIT: Solution in one line is:
UIManager.put("Button.select", newColor);
But it changes all button colors but I need another to have different a color.
EDIT2: After some research I figured out there isn't an easy solution (but it should be). How I see it I have 2 solutions, 1. is to break buttons to separate classes and set UIManager for them, and second is to make custom buttons. It is just too much work for button.
I've found nothing that can change that particular behavior on a normal JButton. The problem being, that whatever you write in your actionlistener for the button, will occur AFTER you've let go of the mousebutton, and not "while clicking".
There are workarounds, however.
My preferred choice is, to remove all graphics from the button, and then add your own images to the button's regular and pressed states. You could take a screenshot of your GUI, cut out the button, and set that image to be both states.
JButton myButton = new JButton();
// Sets button x, y, width, height. Make the size match the image.
myButton.setBounds(5, 30, 100, 30);
// Remove border-graphics.
myButton.setBorder(null);
// Remove default graphics from the button
myButton.setContentAreaFilled(false);
// Remove the focus-indicating dotted square when focused (optional)
myButton.setFocusPainted(false);
// Here, myImage is a simple BufferedImage object.
// You can set one like this, provided you have an "images" package,
// next to your main class (ex: com.somecompany.someprogram.images),
// that contains an image:
BufferedImage myImage = ImageIO.read(getClass().getResource("images/myImage.png"));
// Then we simply apply our image to both states for the button, and we're done.
myButton.setIcon(new ImageIcon(myImage));
myButton.setPressedIcon(new ImageIcon(myImage));
Obviously there are many ways to retain and load an image, but since that's not the issue here, I'll leave additional methods out of it.
There's no need to go through it all countless times, though. It should be pretty easy to write your own custom implementation of the JButton class, in which a custom constructor takes a single parameter, being the BufferedImage, and then the constructor sets it up accordingly (changes the icons). Then all you have to do when you create a new JButton, is to use your own class, and pass it an image:
JButton btn = new MyCustomJButton(myImage);
You could also easily get along with very few images. All you need is a HashMap which holds all the images, with a String as a key. Imagine you need 4 OK-buttons. You make a single image of a button with the text "OK" written on it. Then you put that image into the HashMap, like so:
myMap.put("OK", myImage);
Then you could do this when creating a button, over and over again if you'd like more:
JButton btn = new MyCustomJButton(myMap.get("OK"));
Alternatively:
Another way of achieving this, which is pretty elaborate, but probably considered "the right way", is to use ButtonUI, as presented in this answer to another post.
If the OP is referring to the temporary change of background colour on a button with an icon at the moment the mouse is pressed, the following statement does the trick:
button.setContentAreaFilled(false);
"If you wish to have a transparent button, such as an icon only button, for example, then you should set this to false."
This took me a long time to figure out. It seems to be a little known technique, perhaps since its name gives little clue as to its effect.
With only first lane we can still see that it is clicked. You need to combine those two:
button1.setContentAreaFilled(false);
button1.setEnabled(false);
and if you don't wanna in grey color you put another button under him.
panelname.add(button1,+5,+5); \\(first not clicable, not visible button, notice +5)
panelname.add(button2,-5,-5); \(-5,-5 means it is 5 points under panel)

Android UI Best Practices for Display Field turning into Input Field

I'm programming an android app with a list displaying images and some additional information like title, place, etc...
I'm new to the android ecosystem and wondering what are the best practices to implement a list element which normally displays the mentioned information and turns into input fields on a press on the listelement.
Do I have to draw the display elements (e.g. TextField) and the edit element on top of each other and set visible for either display or input? How to handle this generally? Or do I replace the layout responsible for the list element altogether?
I know that for the simple case of a text there is a simple solution for making the EditText field look like an uneditable TextField. I'm, however, looking for a general answer covering broader cases than just a TextField.
Thanks!
you can make the elements of the listview a view flipper having two views.one you textview and other and edittext.
<ViewFlipper
...
<TextView
... />
<EditText
... />
/ViewFlipper>
Then in the onItemClickListener of the list items you can call flipper.showNext();
So, flipper works like, it shows only the first view defined in it and on the subsequent call of showNext() it displays the next view defined in it.
So if you have 2 elements in it, it will behave as the coin with two sides.
So in your situation there are a few ways you can achieve this.
First way is to build a layout which contains TextView and EditText and in first initialization your edit text won't be visible. And in your OnItemClick you have to hide your textview and show editext with value of your current data and option to edit.
The second way which I think is more user friendly is that you can show an AlertDialog after OnItemClick with custom layout where you can change the values and update the listview after user press Yes or do nothing is he selects No.
It depends on you which way you will do that, but I think the second option is the better one.

LWUIT scroll jumping issue

I need to show the only component on the form - HTMLComponent. Reaching the bottom of the form/component while vertical scrolling scroll bar jumps back to the top of the form. I need to prevent this.
I've tried to turn on/off scrolling on the form and HTMLComponent but anyway if there's a scroll bar - it will return to the top from the bottom. Also I've tried border and box layouts and additional container for HTMLComponent - no use.
Any ideas how to prevent such scrolling issue?
Try this (it works for me - LWUIT 1.5):
htmlComponent.getComponentForm().setCyclicFocus(false);
If you get a NullPointerException, call it after adding to the HtmlComponent to a form.
If you want to get rid of the bottom/top jump scroll, you can use
form.setCyclicFocus(false)
You should stick with border layout and place the HTML component in the center for this particular use case. You can disable form scrolling since the HTML component is indeed scrollable by default:
form.setScrollable(false);
HTMLComponent is itself scrollable
to prevent scrolling
setScrollable(false);
for horizontal scroll off
setScrollableX(false);
hope this will solve your issue
...or, you can paste this code on your Form class
public void keyPressed(int keyCode) {
int tecla = Display.getInstance().getGameAction(keyCode);
if(tecla == 8){
//if hit ENTER or principal key in mobile keyboard
}else if(tecla == 6){//down key
if(this.list_component_name.getSelectedIndex() < this.list_component_name.size() - 1)
this.list_component_name.setSelectedIndex(this.lista_bodegas.getSelectedIndex() + 1);
}else if(tecla == 1){//up key
if(this.list_component_name.getSelectedIndex() > 0)
this.list_component_name.setSelectedIndex(this.list_component_name.getSelectedIndex() - 1);
}
}
That's also work for me
form.serScrollable(false) or form.setCyclicFocus(false) didn't work for me.
I have a form and just a single HTMLComponent in it.
The problem is in HTMLComponent itself and disabling focus of the form won't affect it.
You can try with making the whole component focusable which might help in scrolling in a proper way. Along with this you should add your html component in Boderlayout.center of form and make form scrollable true and cyclic focus false.
In LWUITImplementation we have function getDragPathTime(). This javaDoc about this function:
/**
* Indicates what drag points are valid for the drag speed calculation.
* Points that are older then the current time - the path time are ignored
*
* #return the relevance time per point
*/
I also was problem especially in devices with OS S-60 Nokia. Lists was jumped from buttom to top. i solved this problem by change the return value. I change the value to 600( from 200). this occurs to fewer sampling and prevent the "jump".

Resources