Appearance of the button pressed when performing - java

Let me start by saying that I am using the standard buttons.
When you push the button, my program performs a method, and until it does, the looks on down. I would like to change the text in the button when this method is performed, after I would like to have a text as the beginning.
Do I need to encode something? Whether enough suitable property in xml?

This is easily achieved.
First initiate
private Button btn1;
then assign
btn1 = (Button) findviewById(R.id.//id_name_of_your_button);
now add an Onclicklisenere
btn1.setOnclickListener(new OnClick....
when clicking on your button change text or add any other value around
btn1.setText("patrick1980 kick ass!");
Enjoy

Related

How to enable a disabled button by clicking on same button in android java?

I want to disable button and enable it again by clicking on same button in android java app.
I think you have misunderstood something. When a button is disabled, that means that all clicks on it will be ignore. That would include a click to enable it.
In short, what you are asking for cannot work.
Now, you could implement a button that toggles between "on" and "off" states when you click it. There is an existing control for that: https://developer.android.com/guide/topics/ui/controls/togglebutton
That may be what you really need.
What you want:
You need a feature where once the Button is clicked it enters the disabled state and when clicked the next time it should come back to the active state.
Problem:
As #Stephen C pointed out, once the Button is disabled it can't be clicked again and brought back to the active state.
Solution
So instead of disabling the Button, we can just make the user feel that the Button is disabled.
How:
short noOfClicks = 0; //declare it as top level state variable
Button mButton = (Button) findViewById(R.id.your_button);
mButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
++noOfClicks //this counts the number of times button is clicked
if( noOfClicks % 2 == 0 ){ //user has clicked the button from disable state
//do your work here
mButton.setAlpha(1.0f); // this will bring back button to its original opacity
}else { //user has clicked the button from enabled state
//do your work here
mButton.setAlpha(0.5f);// this will grey out the button(actually, it changes the opacity of the button and gives a disabled look to the button)
}
}
});
What Just Happened:
Whenever the user click's the Button, noOfClicks will get incremented by one, the if-else check will determine whether the Button currently is in the abled or disabled state, depending on which we apply setAplha() method which controls the opacity of the Button.
Conclusion:
Honestly speaking we just used an ugly hack which provided a false sensation to the user that the Button gets disabled when he clicks it for the first time and gets enabled when he clicks it for the second time.

Can I change combobox value when a button is clicked in java?

By using doClick() method, the action of a button can be triggered. Is there such a way to change combobox value when a button is clicked in java? Thank You.
As you didn't state the graphical framework I assume you use Swing, as it contains a doClick function.
The doClick() function is only used to emulate a button click programmatically, for example in testing. This will fire all actions that are normally associated with that button, however you need to register those yourself, using a listener.

How to make a hidden "Exit" button in java netbeans?

I want to create a hidden button in netbeans. Suppose if I click a Next button then a new "Exit" button will be appear in the same jFrame. Until I click the Next button the Exit button will not be shown. So how to make it? I mean how to make a button which is by-default in .setVisible(false) in netbeans?
Please help me out about this problem.
Since you already seem to know the proper method I assume you doubt is about Netbeans operation.
Right click in the method and select "Customize Code".
Then you'll have the chance to add the proper code after the button creation.
Use JButton.setVisible(false); right after you create the button.

Android: Make EditText empty when new value

I Want to make my EditText empty when you put a new value. If I use a onClickListener I need first to focus and then to click (Double click), if I use onFocusChangeListener it is already deleting when click another EditText.
Does someone know a other way to achieve this (When first click == empty)?
Thanks in advance!
Don't make things complicated. Simply set android:selectAllOnFocus="true" to your EditText. So, when the user types-in some text and later click the text box, all the text inside will be highlighted - allowing user to type-in new text from scratch.

Can I show up the textbox editor on an image icon in Android?

all,
We know on Andorid, for a EditText, by default, whenever the EditText is clicked, the soft keyboard pops up to let you enter text. When you click DONE, it closes out and put the text directly to the EditText.
Now, what I am trying to do is, instead of an EditText, I have an ImageView which is to let user enter some comment.(So the ImageView actually is an comment icon). I wish whenever the icon is clicked, it pops up the text editor with user previous entered text, again once the DONE is hit, it closes out and I can save whatever text there back to a string member of the Activity. Is that possible?
So far, all I've seen about InputMethodManager is on EditText control, If it is too complicated, I probably just put an EditText into a sperate Activity.
Thanks.
There are many solutions:
One is to use custom dialog: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
Second one is to use a transparent activity on top of that one.
Then you could use FrameLayout and insert another view in an exact position...
I think you should try the frist or second one. Every ImageView can be easily converted into a button by adding onClick event to it.

Categories

Resources