Is there an equivalent for C's getch() in Android or Java? I want the execution to stop until the user does some action, like tap on the screen or maybe press one of the hardware buttons like volume control or whatever is available. Another option would be to show a modal message box window, which does not let the program continue until the user presses on OK. Is it possible to do this in a simple way in Android? What is the simplest way to get something equivalent to getch() function in android?
I need to be able to use this in a Thread as well
There's no getch() equivalent function/method in java.
You must event handlers to do that.
Like having click handler for button,Which let you to some stuff on onClick() method,Once you click the button.
This example might helpful:Button Click Listeners in Android
There's an event listener for android like onCLickListener. Then you can also used Jdialog then set its .isEditable value to false like dialog.isEditable(false);
Related
I'm trying to create an overlay that is triggered when a button is pressed. This overlay is supposed to allow the user to add their contact and I was wondering how can I use fragments to get this effect like you can see in this mockup.
I am in a dilemna over using fragments is the right choice. My reasoning being that I only need to have it do one task that is adding contacts, and thus I do not need a whole activity.
This is what I have on the main activity right now
I would really appreciate any help on understanding how to make this work.
You can use a DialogFragment.
It behaves like a normal Fragment for the most part. Here is a guide for a basic implementation https://guides.codepath.com/android/using-dialogfragment
They appear automatically in the center of the screen. To get it a bit lower like in your mockup you can change where it is in the window. Here is an answer showing such Position of DialogFragment in Android
At the moment I'm trying to figure out how to make a method in my java program set what a button in my project does when is is clicked.
I was thinking about something like
myButton.addClickHandler(event -> command);
where `command´ is a String variable.
Is this even possible? I am thankful for every response!
Can a button itself access the information and check what needs to be done?
If so, you can always add an ActionListener and implement its method actionPerfomed which is going to be called when button is pressed.
I built a Swing application that works with an MSAccess database. I have various buttons to click when clicked--they will disconnect and unlock the database.
Sadly, this is only in a perfect world where users will actually use those buttons and not the little red "x" on the upper right. When some users click that, the database stays locked with a file extension '.ldb' for those of you unfamiliar with MSAccess.
I need to avoid that. Is there any function that I can implement? Like a timeout? I looked up the
DriverManager.setLoginTimeout(10);
method, but that seems to be for login attempts. Is there something for my criteria?
Thanks.
PS: Sadly, i can't use any other database.
Sadly, this is only in a perfect world where users will actually use those buttons and not the little red "x" on the upper right.
See Closing an Application. You can create an Action that can be invoked when you use a button, menu item or when the user clicks on the "X" (close) button.
Simply configure what happens when the "x" is pressed using a WindowListener.
This is done easily using two methods for the JFrame (frame, in the examples below) that displays everything:
1. frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // by default pressing the "x" will do nothing.
2. frame.addWindowListener(new WindowAdapter() { // However, when the "x" is pressed...
public void windowClosing(WindowEvent e) { // this method is called,
... // and you write the body here to allow your program to respond appropriately
}
});
Eventually you'll want to call frame.dispose() to finally close the window.
You can implement additional methods in the body of theWindowAdapter inner class to respond to different window events... see the WindowAdapter interface for methods that can be implemented.
1- The KB5002099 patch deployed in Client computers recently, introduce a bug as a side effect of a security fix.
Here in the link is the description of this patch -> https://support.microsoft.com/en-us/topic/description-of-the-security-update-for-office-2016-december-14-2021-kb5002099-10670400-427f-4819-8de6-abd11e73100b
Inside this description, you will find the Know issue of this update, and the solution (KB4484211) How to get and install the update
Databases on network share can't be accessed by multiple users in Office 2016 (KB4484211) (microsoft.com)
2- Select download update for Office 2016, This update is available only for manual download and installation from the Microsoft Download Center.
https://support.microsoft.com/en-us/topic/databases-on-network-share-can-t-be-accessed-by-multiple-users-in-office-2016-kb4484211-88a51f7f-f7dd-2d9c-0b96-b7fca0867a4f
Is it possible to simulate a click on a button, similar to doClick() but just graphical simulate it, not generate any ActionEvent´s. If know that i can extend the class, do my own doClick with a simple if-statement. But is it any other possibility?
I want to this because I have a button that the user can press, but sometimes the computer (it s in a game) "presses" the button. All the logic is done in another thread, I just wanna display it for the user.
if you dig into the details in the look and feel you're using, you might be able to see how it detects and paints the button in its "down" state, and then simulate that?
or you could extend/implement ButtonModel, and mess with the setPressed/isPressed state?
I think the simplest solutions is to just check the model in the ActionListener.
I don't see a way to distinguish between the two; the model is oblivious as to who calls its methods. Instead, you could save all the listeners, invoke doClick(), and restore the listeners. It looks like you would have to check action, change and item listeners.
If you want to click on the button try this:
try
{
robot = new Robot();
robot.mouseMove(0,500);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}catch(Exception e){}
But maybe you will prefer to simply disable the button when the user shouldn't click it
Button.setEnabled(false);
You can set whether it's enabled or not, so use "buttonName.setEnabled(false);"
My activity A is a game and it does some background operations. When I press a button in the contextual menu, I want to pop up a "small window/dialog/subactivity" (lets call it B) that appears on top of activity A and displays some data about those background operations. But I need to keep the focus on the activity A in order to continue interacting with it (playing the game).
In essence, I want to be able to see the data display by B while playing the game.
I'm not really sure how to implement this. After reading the documentation I have the next conclusions:
I know that I can't use Dialogs because the have the focus. Is it possible to avoid this?
Using a subactivity with a Dialog theme it's another option that looks tempting...but I believe that the subactivity has the focus. Ditto.
My last option is to try to add a LinearLayout with my data to the main Layout, "sharing/splitting" the screen. It's not pretty, but at least I know that this is possible. What I don't like about this approach is that I use the width and height of the screen.
Any suggestions? Solutions?
PS: I found some this thread here that are very related to my question:
Android ==> Sub Activity?
Create an Activity with style Theme.Dialog. This is a normal activity which looks like a dialog, while being modeless and accepting events.
Additional catch is in setting WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL and resetting WindowManager.LayoutParams.FLAG_DIM_BEHIND.
See this answer for complete example: timed modeless dialog
Why not use a FrameLayout that is apart of your Activity? Just ensure that this View has a higher z index (make sure you declare it last in your XML layout or create it at runtime). That way you never leave your Activity.