Android Switch Button Get Text - java

The question is straightforward enough... Is there a way to get the text off of an android switch button in code? No, I don't mean by checking if the switch control is checked and then just pulling the textOn/textOff text. Reason is, I need to pull the text while the user is dragging the control over to the on/off position. I need a way to pull what is currently be shown because I will be acting on the state change on drag not on checked. I already tried mySwitch.getText(), but it is empty. Any help is appreciated. OR, if you have a solution in determining when the user drags the switch all the way to the on position or the off position. Again, not using the onchecked listener since this is only triggered after the user lifts there finger from the switch control. Just when dragging the switch. Thank you.

Use getTextOn() and getTextOff() to get the text. That said, I don't understand why you need these and why you cannot use the OnCheckedChangedListener -- Switch does not have a "dragging" state, it's a binary state on or off. It's basically a fancy CheckBox.

Related

Custom button with a selection

I don't know if this has been asked before. I am going to be building a calculator for my dad. He asked me if there is any way to have customization with the buttons.
I have not done any code yet. I plan on trying a few things. My research has come up with nothing.
This is what I am trying to accomplish, I have a feeling it breaks the android studio law of coding. This is the concept:
Imagine the calculator. You have 8 blank buttons above the numbers. Those buttons ordinarily have the functions such as percent and sqrt.,..etc.
I have been asked if it's possible can he just hold the button and change those functions at will.
So the question at hand is. Can I do if statements to change the symbol and the code for a particular button when long pressed?
The concept of the calculator would be in portrait mode he can customize the buttons to the functions he uses without having to turn the calculator in landscape mode?
So in theory you have a long press which would bring up a selector. He can select any math function and based on that function the symbol and code would change and the button will work properly to the new selection?
I was going to to build the calculator as a standard. But was also wondering myself if this is possible. I know the buttons serve as a one function but in coding anything is possible.
Any help or advice would be appreciated. If this can be done it opens new possibilities to app features to only show what you want and not a predefined controls.
*******once I try a few codes I will edit question to better see the issue and what I am trying to do.
OnLongPress show a dialog with the option you want and change the button text according to selected option.
On Onclick check the button text and call function according to the text

How can I create a popup menu that allows user to choose a certain elements from a list on Java?

I am writing a Java program to record some events and their status, i.e., done or not. I have implemented the recording and calculations, but I also want to have a button that will open another window that will list the events with a checkbox corresponding to each of them, so I can pick which ones' statuses I will change to done. I have only used Swing libraries so far.
I want this window to contain one event per line, with a checkbox next to the event. Each checkbox should determine whether the status of the even should be changed or not. I had trouble even making such a window open and list the items, let alone put the checkbox.
Note: The design is not too important. This won't be a published project, I will mostly use it for personal work. I can do with buttons instead of checkboxes, where any click changes the status of the event next to it.
Thank you in advance for your valuable responses.

I want to make a program that recognize a button that is in the League of Legends client

I want to make a program that recognize a button that is in the League of Legends client, and when the queue's button shows up the mouse instantly click on it.
Its a sort of a AutoAccept Client...
There is already a program that someone did, but it has so many unnecessary things and it does not work very well....
How do I do to recognize a element inside a program to make my mouse move there when it shows up?
I can try to code this in any language, just gimme a tip pls
You can create a program that takes a screenshot every 100ms, use a recognition algorithm of your choice and then (optionally) performs a mouse click. There are enough libraries that can screenshot for you, you should be able to recognise the button by colour and location and every language should have some method of controlling the mouse.
Sikulix (can be paired with python) is a perfect tool to use for this. It scans over your screen constantly, and if the image in question pops up (the accept button) you can click on it.
You will have to take a screenshot and likely store it as .png so the program knows what it is looking for.
Google Sikulix.

Appropriate way to invert/highlight a button in android

In my app I dynamically create a list of buttons. The user should be able to click on them. A short click would select the buttom as the current item, while a long click should enter the editor for this item.
Now I wonder how I can determine and set the colors that i should use. My first idea was to simply read the background and textcolor and switch them, however I'm not sure if this would be really the appropriate way to do this. So I was wondering if there is a an appropriate way of how to retrieve colors.
Of course I could hardcode some colors, but I don't know what color scheme the user has set and they might not be visible in a good way.
Please note, that, since I have to create the buttons dynamically, I can not set it in the XML.
You could simply use a ToggleButton, so android will take care of marking a "clicked" button as selected.
Since ToggleButton is a View, it has a setOnLongClickListener(Listener)-method, which can be used to make the ToggleButton long-clickable.

What is "focused" regarding android apps?

I keep seeing "focused" and hearing about "focusing" within the development of Android apps. My question is: What is focusing, and how is it applied within Android apps? Is it important? What can you do with it?
I'm sorry if this has been asked, I looked but didn't see anything that clearly explained it. I've looked the the Android development guide, but I couldn't find a decent explanation of what it is and how it works.
Focus is simply giving a specific view "focus", or attention.
One example of using focus is if you have an EditTextView and you want a user to be able to type into it as soon as it is displayed, you would give focus to that EditTextView and the keyboard would automatically be displayed in accordance to typing in that view.
If you've ever used a blackberry and browsed the web via that, you'll remember that whenever you scroll the wheel you sort of select random elements on the page until you find what you want, then click enter. You know what element you're selecting when the elements change colors, or become focused. That's essentially what's happening with 'focused' on ANdroid, except it's mostly used for when you're scrolling via some kind of buttons, or when you select a textbox or something and it's waiting for input.
It is just referring to the view that is active. For example, if you have a TextView and it is the active view then it would be in focus
Simply put, an object/item that has the user's attention for interaction is focused. It is a state an item can be in.
Android Dev UI Events

Categories

Resources