I wrote this code to disable using another button by clicking this button in Java/Android Studio but it is not working.
public void btnPowerCheck_onClick(View v) {
SendMessage("43");
Button ButtonBtnPowerCheck = findViewById(R.id.btnPowerCheck);
ButtonBtnPowerCheck.setEnabled(false);
}
Thanks for response, It was my problem, I entered tags and ids wrong
Related
I am creating an app that tracks the inventory for a shop.
The layout consists of a ListView that has a sale button for each item, and on clicking the sale button, the quantity of the item should be decreased by one and be updated in database.
So my question is how do i set the onClickListener to the button so that it also receives the id of the item for which the sale button was clicked for, as it will enable me to update only the specific item in the database.
This is an sample example
The Button in the fxml file must have an fx:id so that you can use the button properties in the code behind
it looks like this
<Button fx:id="myButton"/>
and then you can use it (e.g. in your controller) like that
myButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO
}
});
please check this also setOnClickListener
I Created a button on my codename one frm but when I click on the button it does not perform the Action Event. I tried removing the Button and to recreate but it does not work.
Using something like:
Button b = new Button("My Button");
myForm.add(b);
b.addActionListner(e -> {
ToastBar.showInfoMessage("Hi There");
});
Works for me.
I want to make a button which will post a message once the button is hit. Here is my main activity.java :
enter image description here
But I confuse why I cannot choose the onclick option for the button :
enter image description here
or I dont have to choose the onClick button option again ?
Hope you undestand my question, and here is my video reference from youtube :
"Android Tutorial for Beginners 8 # wrap_content, fill_parent, Password Field and Toast in Android" Uploaded by : ProgrammingKnowledge
Replace the onCreate() method as
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListnerOnButton(); //Add this line to your code.
}
you are doing wrong in android you can set click listener by two ways
1. In Java code
2. In XML
in your example you are doing runtime in java code so it will not show in XML editor
in your case just call your addListenerOnButton in onCreate it will work
if you want it in xml
add onClick function in activity class as below
public void buttonClick(View v)
{
//do what you want
}
then this buttonClick will be shown in editor or you can directly add in xml button onClick attribute
<Button ...
android:onClick="buttonClick"/>
So I'm trying to make a kind of Wheel of Fortune game or Hangman. I have 33 buttons which represent the alphabet, 1 button = 1 letter. When a user presses one, it has to 'dissapear' (become disable and invisible). I created all the buttons in the SceneBuilder so they are located in the FXML file.
How do I actually do that? I created this method for the first button. But it doesn't work properly, no matter what button I press the first one dissapear. Is there an easier way to do it wIthout writing 33 different methods for each button?
public void letterChosen (ActionEvent evt) {
b1.setDisable(true);
b1.setVisible(false);
The Button that was clicked is available as the source of the ActionEvent.
Additionally userData could be attached to the Button, in case you cannot get the necessary information to handle the button click from other properties of the Button:
public void letterChosen(ActionEvent event) {
Button source = (Button) event.getSource();
source.setVisible(false);
System.out.println("pick: "+source.getUserData());
}
FXML
<Button onAction="#letterChosen" userData="a" text="A"/>
<Button onAction="#letterChosen" userData="b" text="B"/>
Note that it isn't necessary to disable a Node that isn't shown, since a Node that is not visible cannot be interacted with. a disabled Button will appear "faded" by default, but could also be shown differently, e.g. using CSS.
I have a text box with a valuechange handler :
#UiHandler("box")
public void box_onValueChange(ValueChangeEvent<String> event) {
window.alert("allright");
}
It works great if i lose focus by clicking elsewhere. Except when i click on a button.
Is there a trick i didn't see ? Should i hack my onclick event to fire the valuechangeevent anyway ?
Thanks