How to hide a button programmatically?
You can use the following code:
playButton = (Button) findViewById(R.id.play);
playButton.setVisibility(View.VISIBLE);
playButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//when play is clicked show stop button and hide play button
playButton.setVisibility(View.GONE);
stopButton.setVisibility(View.VISIBLE);
}
});
Android studio Hide and Show buttons from a condition
From your comments, are you saying you need to check:
if(Cars.payment) {
btnDone.setVisibility(View.GONE);
btnPaid.setVisibility(View.VISIBLE);
} else {
btnPaid.setVisibility(View.GONE);
btnDone.setVisibility(View.VISIBLE);
}
Hide and Unhide button programmatically
Use UITextFieldDelegate to hide and show button.
class ViewController: UIViewController,UITextFieldDelegate //set delegate to class
@IBOutlet var txtValue: UITextField //create a textfile variable
override func viewDidLoad() {
super.viewDidLoad()
txtValue.delegate = self
YourButton.hidden=false;
//set delegate to textfile
}
func textFieldDidBeginEditing(textField: UITextField!)
{ //delegate method
YourButton.hidden=true;
}
func textFieldShouldEndEditing(textField: UITextField!) -> Bool { //delegate method
return false
}
func textFieldShouldReturn(textField: UITextField!) -> Bool { //delegate method
textField.resignFirstResponder()
return true
}
May be it will help you.
how to hide/show a button in swift
As @LAmasse says, you want to use button.hidden = true
. button.hidden
was renamed to button.isHidden
in Swift 3
The code you posted doesn't make sense.
if self.Status.text == "Closed"
{
Purchase().enable = false
}
What is Purchase? From the capitalized name, it seems to be a class. If so, the expression Purchase()
is likely creating a new instance of the Purchase
class, which makes no sense. Why are you making a function call? If that is creating a new Purchase
object then that code is pointless. (You would create a new object inside the if
statement that would be discarded on the very next line since you don't keep a strong reference to it.)
You want to set up an IBOutlet for your button and connect it in Interface Builder.
The declaration might look like this:
Class MyViewController: UIViewController
{
@IBOutlet weak var theButton: UIButton!
//The rest of your view controller's code goes here
}
If the outlet is connected to your button, there should be a filled-in circle to the left of the line of code. It looks like this:
And then your code to show/hide the button might look like this:
func showQueryResults
{
var query3 = PFQuery(className:"Status_of_game")
query3.findObjectsInBackgroundWithBlock()
{
(namelist3: [AnyObject]!, error : NSError!) -> Void in
for list3 in namelist3
{
var output = list3["StatusType"] as String
self.Status.text = output
println(output)
if output == "Closed"
{
theButton.isHidden = false //changed to isHidden for Swift 3
}
}
}
}
It isn't clear to me why you'd loop though all of the results from your query and and show the button if the "StatusType" of any of the results is == "Closed".
Finally, I'm not very familiar with parse. If the completion block for the findObjectsInBackgroundWithBlock method doesn't get called on the main thread you will have to change that code to make the UI updates on the main thread.
EDIT:
I've since learned that Parse executes its completion handlers on the main thread, so you don't need to worry about UI calls from Parse completion handlers.
How to hide a button in Swift 4 programmatically
Not True finishButton.isHidden = false
True way is finishButton.isHidden = true
Hide Toolbar Home / Back button programmatically in Android?
If you're using a Toolbar
you can use its own navigation icon API.
You can change the icon using:
toolbar.setNavigationIcon(R.drawable....);
In you case you can use:
toolbar.setNavigationIcon(null);
You can add add an OnClickListener
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
//...Do something
}
});
You can use an androidx.appcompat.widget.Toolbar
or can use a MaterialToolbar
included in the Material Components library.
Angular Hide With Button
Your HTML
<div class="yourCssClass" *ngIf="this.isButtonVisible" (click)="this.isButtonVisible = false">
...
</div>
Your TypeScript
export class AppComponent {
private isButtonVisible = true;
}
This should do the job. *ngIf
automatically hides the element, if the condition evaluates false
, so setting the variable to false
is sufficient.
The problem I see here is, that you don't control the visibility at any point. Using [ngClass] to add a specific class, if a condition is met, or *ngIf
is helpful, whenever you try to change elements on user interaction.
For more information on [ngClass]
, you can read about its usage here: https://angular.io/api/common/NgClass
You can read about *ngIf
here: https://angular.io/api/common/NgIf
Especially the "Common Use" part should be interesting for you.
Edit:
Reading your comment below it seems you did not notice what [hidden]
and (click)
actually do. [hidden]
controls the visibility of the element, usually dependent on a certain condition. (click)
however is a quick way to bind a Click-Event to your element.
Using both of those tools enables to hide an element, by changing a variable, if a user clicks on your element (the new value of the variable may be assigned by a function called by (click)
or inline, as demonstrated in the example code).
Edit2: Yep, you meant Angular2/4 ;) So this should do the job.
How can I hide/show a layout when a Button is pressed
You should be able to call
view.setVisibility(View.GONE);
in your onClick()
method where view
is the variable name for the View
that you are trying to make disappear.
Related Topics
Low-Latency Audio Playback on Android
Toggle Button Using Two Image on Different State
Cardview Layout_Width="Match_Parent" Does Not Match Parent Recyclerview Width
How to Style the Standard React-Native Android Picker
Launch Skype from an App Programmatically & Pass Number - Android
How to Parse This Nested JSON Array in Android
Appropriate Multiplication of Matrices for Rotation/Translation
Eclipse Reports Rendering Library More Recent Than Adt Plug-In
Add Floating Point Value to Android Resources/Values
How to Make Custom Dialog with Rounded Corners in Android
Gradle Build Fails on Lint Task
Is Secure.Android_Id Unique for Each Device
How to Change Focus Color of Edittext in Android
Java.Lang.Nullpointerexception (No Error Message)
Gradle Dsl Method Not Found: 'Compile()'
Org.JSON.JSONobject Cannot Be Converted to JSONarray in Android