Android Studio detect when a switch's text is clicked - android-studio

As the title says, I am trying to make something happen in my application whenever a switch's text is clicked.
How can I implement this ? A simple onClickListener only detects whenever the switch is clicked
I tried many different methods but none of them worked for me. I am a beginner

Related

How do control buttons know they've been clicked?

I have written an application in c++ visual studio 6 that looks for the WM_LBUTTONDOWN message to carry out a certain task. This works fine except when using a touchscreen. The Wm_lbuttondown or any other button message is not sent when the screen is touched. However, the control buttons still operate normally, so they know they are being clicked. I would like to know how the buttons detect the touch. I would like to detect when the screen is touched in a similar way to how I detect a mouse click. Is there a different WM I can use other than WM_LBUTTONDOWN?
My old version of visual studio doesn't seem to recognise WM_TOUCH so I haven't been able to try that.

Google Android first application tutorial appears to be out of date

I'm trying to follow Google's Android tutorial to create my first application, but either I'm looking in the wrong place or the tutorial is wrong/out of date for the latest version of Android Studio.
On the page I linked above, to add an onClick handler in the Design view of Studio, it contains the following instruction:
However, in the Attributes window, there is no onClick item. I could only add the onClick handler by editing the xml in text mode. Here's what my screen looks like when I have the button selected:
However, after I add the onclick event to the xml file, it does appear in the Attributes window.
Is the tutorial wrong, or am I doing something wrong?
I don't know what version android you used, but in Android Studio Chipmunk, you can see onclick property at Common Atttributes
If you don't see Common Attributes, please check icon setting below Design button

When switching Layouts in Android-studio, how to go back if there was no layout when app started? Or how to un-set a new layout?

I‘ve developed a game in Love2d (Lua), and used love-android as the tool to make it run on android-studio. The game works perfectly in Android devices, so now I’m trying to add billingclient.
My problem is, the Project created by love-android has only 1 activity (gameActivity) that extends SdlActivity. Somehow it runs the zipped game .love, but it has no layouts.
So, when I create a button so players can buy in-apps, I set a layout. But after the onClick, I cannot get rid of this button layout, because I have no layout to setContentView back. I’ve also tried to hide the billing layout with “GONE”, “INVISIBLE”, button.enable(false), but it just goes to a black screen. Since I’m new to Android Studio and still haven’t found how the game runs after the android tool is used, I’m not sure even if it is still running after I call this button. Any suggestion on how can I implement a full working button in such case?
If you need more info, I’d be happy to provide it.

MonoTouch Dismiss Keyboard (sort of)

I am writing a MonoTouch iOS app. I have read many postings about ResignFirstResponder and I am using that.
My app is a typical table view app. I have done my own custom table cell view. The UITextField controls that cause the numeric keypad to come up in the first place are all on the custom table cell.
Currently I have it so that if you tap on the background of the cell I call ResignFirstResponder on all the text fields. This seems to work, but is not intuitive. I had a new beta tester get it last night and he tapped on one of the text fields and the keypad came up and he was lost as to how to get rid of it. After I told him to just tap the background, he now is fine, but obviously I want a solution that is obvious and doesn't require me to tell everyone how it works.
I read one post about a way to add a DONE button to the keypad, but it looked like a total hack and even broke when 3.2.1 came out and I don't want to have to worry about my app breaking when a new OS comes out.
Suggestions?
I would keep the background click->ResignFirstResponder that you have already, but add to it.
Curious, what button do you have set in the bottom right of the keyboard? There are options to show a Done, Search, Go, Next etc. buttons that can be setup to ResignFirstResponder. Pick the button that makes sense in your situation.
You can hook into the bottom right button by setting a callback to UITextField.ShouldReturn and calling ResignFirstResponder. You can just return false (that return value is for allowing line breaks in your UITextField).
Found an example here of hooking up ShouldReturn.

A keyboard with a UITextField

I have a table listing some strings, and what I want is when I tap the add button on the navigation bar, a keyboard with a textField would jump up, so I can input a string in the textField, then when I tap the return key, the keyboard disappear as well as the textField, and the new string is added to the table.
I already make up a nib file with a toolBar containing a textField, and I just failed to go on.
How can I implement this idea? Use the inputAccessoryView? If so, that means the inputAccessoryView of the textField which belongs to the toolBar is gonna be the toolBar itself!
This seem kind of weird and I have not been able to make it work till now.
Or is there another way for this idea?
Thanks a lot!
I've solved the problems by using notification instead of inputAccessoryView.
There is a sample code in XCode called "KeyboardAccessory", and it gives a good example about using keyboard notifications!
Or custom a view with a tab, and set it as the textField's inputAccessoryView, that would also work!

Resources