Skip to content
Advertisement

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.

Advertisement

Answer

  1. OnLongPress show a dialog with the option you want and change the button text according to selected option.

  2. On Onclick check the button text and call function according to the text

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement