Android: OnClickListener of Button on CardView - onclicklistener

I'm a bit of a newbie so I apologize if this is an easy question.
I'm following this tutorial: http://www.truiton.com/2015/03/android-cardview-example/#comment-7174
It shows how to make a few CardViews in a layout with 2 TextViews in each - all programmatically.
I would like to modify it to have a Button instead of the TextViews and to have each Button make a Toast notification upon press. I am currently stuck because I have no context to make the Toast with (because I can only access the buttons in the MyRecyclerViewAdapter class). How may I solve this?

Well the fact that you have access to a button, means you have acces to a context. and to my knowledge, a onclick event on a button means that the button is still alive, and then you could assume that the context for the button is still active. The way to get the context from a view is very simple:
view.getContext();
The reason i mention the assumtion is that, relying on a view's context, could be a bad idea (for example after calling a webservice or something else, where a view could have been destroyed).

Related

(NSWindowButton) NSWindow.standardWindowButton button not highlighting

When i use the following to create a button
NSWindow.standardWindowButton(NSWindowButton.ZoomButton, forStyleMask: 0)
I get a button that doesn't react to mouse hover events. I can augment this by creating a container view with a NSTrackingArea and manually triggering the highlight method but it produces a clicked state.
Is there a way to somehow force the button into the expected behavior state without the darkened background?
I have been trying to avoid subclassing NSButton, but it seems like i may have to, and I'm just in a state of denial.
I could not get this working for the life of me so my solution was to write my own custom buttons. This works fine for me because my NSWindow is already custom so there wont be a clash of style.
https://gist.github.com/icodeforlove/a334884e59784b4c2567
Another viable solution is to use https://github.com/indragiek/INAppStoreWindow as #xhruso00 mentioned, but it seemed like overkill.

Showing an NSSharingServicePicker on MouseUp

I'm adding sharing to my app (targeting Mavericks, 10.9), which I want to work like this:
User clicks Share button
Cursor changes to crosshair
User drags selection of what he'd like to share
NSSharingServicePicker displays, allowing the user to pick the service to share with
I'm accomplishing this using the -mouseDown:, -mouseDragged:, and -mouseUp: events. mouseDown begins the selection, mouseDragged provides feedback as to the area being selected, and then mouseUp completes the drag, showing the picker. Each time, though, I get this written to the console:
2014-06-25 00:13:45.111 App[31401:303] Warning: -[NSSharingServicePicker showRelativeToRect: ofView: preferredEdge:] should not be called on mouseUp
Please configure the sender with -[NSControl sendActionOn:NSLeftMouseDownMask];
I don't understand why that would be a problem, unless you were showing it from a button click on mouse up. Should I ignore the message? I've tried showing it using dispatch_async and dispatch_after to try and get it to run outside the event's invocation, but they didn't work. I suppose I could ignore it, but does that leave the door to deprecation open?
I know this is a year late but,
I had the same problem. After some research, I cam back with this answer. Before I implemented this code, my button would spin for a while, and then return with the same error you had. When I click my share button now, it no longer lags, and does not return any error. Insert this into your app's awakeFromNib method:[yourShareButtonName sendActionOn:NSLeftMouseDownMask];.
This is what your code should look like:
- (void)awakeFromNib {
[yourShareButtonName sendActionOn:NSLeftMouseDownMask];
}
I hope this helps!

xcode two uitabbarcontrollers one page. auto-rotate issue

Summery:
I have a custom UITabBarAutoRotateController which returns YES from shouldAutorotateToInterfaceOrientation. This has no effect.
If I minimize and show the app again, the rotation issue goes away.
How do I refresh the screen so the user does not have to do this (so rotation works again)?
Details (setup graphically, so no code):
I have two UITabBarController in MainWindow.xib. I only want one to show at a time. So I am linking graphically rootViewController = tabBarController_name1. There is also tabBarController_name2.
I will also have an alert MessageBox for a user to choose what type of application they need, and it will choose a tab bar controller based on their request (per customer definition). This is commented out for now.
There is a bug with Rotation when two UITabBarControllers exist on the same xib. When I try to rotate the screen, it stays upward with wherever the main screen button (power button looking button) faces. HandleOrientationChange does not get called on the active custom ViewController being shown.
The reason I believe it's a bug is because if I hit the main screen button (minimizing the application), and click back on the application (brings it back to the foreground), rotation works perfectly!
Sorry for making you read all that mumbo :). My true question is, "Is there anyway I could refresh the main window or likewise UITabBarController's to get rotation working (without requiring the program be minimized and shown)"? A work-around, if you will?
p.s. I cannot use Storyboard for backwards compatibility reasons. The customer will be receiving this code/project. So I would like to keep this in one graphical page, rather than hiding/showing UITabBarItem's.
EDIT: two-uitabbarcontrollers-and-autorotation and uitabbarcontrollers-and-uinavigationcontrollers were both helpful, but did not address "why" this issue happens. "noob" here when it comes to xcode :)
Tab bar controller inside a navigation controller, or sharing a navigation root view is the answer. Do not use a TabBarViewController. Which, as a noob, I'm not quite sure why TabBarViewController exists (or at least isn't depreciated).
Dragging two TabBarViewControllers into the same page should result in a warning saying that you probably want to implement TabBarViewController by making a custom UIViewController and attaching a plain UITabBar to it.
Frustrating...but finally making progress :)

MonoDroid Click Delegate and Swipe Detection

I have a checkbox with a custom image for the button. I used the click delegate to perform an action whenever the button is clicked:
box.Click += { //do some stuff... }
This is working great.
However, now I have been given the requirement to add swipe detection to this checkbox (Sounds crazy but it does actually make sense for this app).
I added the swipe detection using the standard methods I am used to with normal Android in Java: I subclassed GestureDetector.SimpleOnGestureListener and also implemented View.IOnTouchListener.
I added the swipe detection to the checkbox as follows:
/*
SwipeListener implements View.IOnTouchListener
SwipeDetector is a subclass of GestureDetector.SimpleOnGestureListener
*/
SwipeListener listener = new SwipeListener(new GestureDetector(new SwipeDetector(this)));
box.SetOnTouchListener(listener);
When I do this, the swipe works great. But the click delegate no longer gets activated. I tried moving my code for the click to my SwipeDetector class, and that seemed to work.
But then I noticed that my checkbox was no longer getting its checked/unchecked state and so my custom image for it never changed.
I know this has got to be something simple, but I'm not seeing it... What is the proper way to have a click and a swipe on a view (checkbox) in Android/MonoDroid?
My guess without seeing your code is that you are returning true from OnTouch, meaning you have consumed the event and do not wish any further processing to occur using the event. Try returning false if you want the rest of the event to fire.
http://developer.android.com/reference/android/view/View.OnTouchListener.html

Mouse event is not detected on my NStableview + cocoa

I have been trying this for past few days but couldnt figure it out.
I have an application which has a NSOutlineView and a NSTableView. Outlineview takes input a path and displays them in the form of a tree structure its sub contents. So when ever a user clicks on a particular folder in the outine view, the contents of the folder should be displayed in the table view with their attributes in the form of a list.
Now i am able to display in both the views respective contents and the interaction between the outlineview and tableview is done using delegates and notifications.
Now my problem is I want to have mouse events to be detected in both the views so that i can make my app more interactive by enabling single click to select, double click to enable opening the file/folder and control+click to enable a contextual pop up menu. but strangely no mouse events are getting detected.
my design of the app is pretty simple with each of table and outline views having their own view and controller class and interactions between them using notifications. Please can you guys suggest me where i am going wrong?
I know i can get single click and double click to work using setAction and DoubleAction methods of table view but i cannot get control click to work. I want to know whats wrong with my app design as non of my views are detecting mouse events :(
Thanks
You can get whether Control is pressed with:
if([[NSApp currentEvent] modifierFlags] & NSControlKeyMask){
//control was pressed at the time the event was posted
}
Or you might want to subclass the NSTableView/NSOutlineView and override mouseDown: to get the event directly.
Also, if your action and doubleAction aren't working, verify that the target/action are correct with something like:
NSAssert([[theView target] respondsToSelector:[theView doubleAction]], #"target/action is wrong");

Resources