How to keep validation over this cart button? - android

Kindly check this link , in this on click of cart button ,it shows animation that its added to cart , but i want to keep a validation over this button ,then only it should get added to the cart . Please help me with this code
https://github.com/truizlop/FABRevealLayout

You've got two possibilities:
1) Override the clickListener from the library by registering your own at the FloatingActionButton using fabButton.setOnClickListener(myListener). Make sure you're doing that after the fabRevealLayout has been inflated and initialized. In onCreate() after calling through to super.onCreate() should be fine.
Inside your own clickListener, you perform your validation and based on the result manually trigger the revealing of what the library considers the "secondary view" (fabRevealLayout.revealSecondaryView();) or do not.
2) Register a onTouch listener to the fab button. Inside that touch-listener you check whether it is an ACTION_DOWN event and then do your validation. If it succeeds, return true to notify the system, that the event has not been handled by your functionality (that it has "consumed" the event). Downside: No click sound when pressing among others, so "not the nice way", as we're interfering the android touch handling. On the other hand you do not have to manipulate the third party library.
I would recommend going with the first option.

Related

Getting continuous input from a button in unity2d

What is the equivalent of GetKey for buttons. In my android game when user press and holds the button , i want player to move right but it only moves for one time when i press the button.But when i get input from a keyboard with GetKey function , it moves until i stop holding that button. I want to use my button like GetKey.I tried to add a event trigger pointer down component into my button but it is not working.What should i do?
public void moveRight(){
rigidbody2D.velocity = new Vector2(moveSpeed,rigidbody2D.velocity.y);
}
void Update () {
if(Input.GetKeyDown (KeyCode.Space)){
rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, jumpHigh);
}
if (Input.GetKey (KeyCode.A)) {
rigidbody2D.velocity = new Vector2(-moveSpeed,rigidbody2D.velocity.y);
}
if (Input.GetKey (KeyCode.D)) {
rigidbody2D.velocity = new Vector2(moveSpeed,rigidbody2D.velocity.y);
}
}
they are absolutely same but i don't understand why its not working continously.
Update method is the key, i know this but i don't know how to get information about is a button pressed in Update method.Stuck help.
Well, we have two different parts of Unity3D API here.
Let's split it up into pieces:
Input.GetKey
As stated in API docs, Input.GetKey just checks if certain key is pressed:
Returns true while the user holds down the key identified by name. Think auto fire.
If you check it every frame, (Update() is executed every frame) you re-check if button is pressed and if so, proceed with velocity change.
EventTrigger
EventTriggers are a little different. They actually bind a delegate (UnityAction to be precise) you pass to them and trigger it as callbacks on given EventTriggerType fired. So if you bind to OnPointerDown() with your moveRight(), it will fire when pointer goes down over GameObject. If you keep the button pressed, it won't fire again because actual event of pointer going down has already happened and it already fired appropriate trigger you passed to it. Pointer is actually not going down right now. It's pressed.
It all goes down to the fact that one part checks every frame if button is pressed while the other one fires when button press happens.

Android app - delete item from list following an action in another activity

I'm creating an app where I display a list of pending challenges. When the user clicks on a challenge, he can accept it or ignore it.
Here's what I want to do and I don't know how :
if the user accepts or ignore the challenge, call this.finished and remove the challenge from the list
if the back button is pressed, do nothing, the challenge is still visible
In short, if the user really responds to the challenge I don't want it to be displayed in the list, but if he doesn't choose any option and press the back button, he didn't choses one of the two actions so I want that challenge to still be visible in the list.
I don't think it's possible to detect what button I've pressed when i go back to my main activity. I've thought about using global variables, but I don't want to misuse them either.
Just to be clear, I'm not asking how deleting a list item. But when to know deleting one depending of the actions of another activity.
Give your second activity the index you want to remove as a parameter inside the intent and let it finish by returning the index again as an intent extra (by using setresult(Intent i) and then calling finish) inside your first activity catch the result from your second activity by overwriting onActivityResult (http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent))
see 3.3. Retrieving result data from a sub-activity in http://www.vogella.com/tutorials/AndroidIntent/article.html for a detailed howTo

Button stays disabled until second click?

Good Morning,
I have a list of items with a prev. & next button. When the user is at the start of the list the prev button is disabled. Clicking next takes them to the next record and my click handler sets the prev button enabled true. However in the emulator it doesn't show the button enabled. Clicking next moves me to the third record and again the handler sets the prev button enabled but this time it does become enabled in the emulator. I'm grasping at straw here but do I need to invalidate and redraw or something?? I don't understand why such an elementary task is not working.
In XML:
<Button
android:id="#+id/btn_PrevLift"
...
android:enabled="false"
android:onClick="btn_PrevLiftClick" />
In the handler code:
private void UpdateNavButtonStatus(int z)
{
...
btn_Next.setEnabled(true);
btn_Prev.setEnabled(true);
....
}
No just to show you how little I know about what I'm doing how come when I look at the variable values in Eclipse debug I can't see the enabled property in any state???
More Info
Very odd to me at least. If I move from using XML defined event handlers to programatically defined as below it works great!!!???
btn_Nxt.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//Call helper methods etc...
}
});
I think I have it but not sure exactly why
So when I was trying to get a handle on my Button objects I was using the View.findViewById(etc). When I changed from XML to the programatically declared event handler I used ViewGroup.findViewById. Reverting back to xml if I use the ViewGroup I get a "different" handle that seems to work...????
Ok,so what you can do is declare a variable count and on the click f button next increment the value of count..and on the click of Back button decrement the value of count and give the condition that while count<0 the task of the back button is done else nothing
I have identified the problem and of course the problem is me. I was enabling the button and then the ListView was updating to the next record. Of course my enabled button was one behind so it appeared that when I clicked a second time the button suddenly enable but that is not the case. When I clicked a second time we moved to record three and showed button for record two which was enabled.
See my buttons were part of my ListView and new buttons were being drawn for each record. OOHHHH it makes so much sense now how everything was behaving.
Anyway I moved the buttons off the ListView layout so they remain constant as the user navigates through the records.

Android - Manage click and longclick in listview

I am currently coding a new android Application, and I need to use both OnItemClickListener and OnItemLongClickListener on a listview. Each listener launch a different actionmode on the actionbar.
The problem is that the actionmode associated with the click event is the only that is launched even if I perform a longclick.
After some research, I understand now why : a long click event also create click event, and I guess that this last event is always perform after the long click event, so that explain why I can't manage to display the other actionmode.
The question is : how can I block the click event when i do a longclick ? Or does it exist another mean to perform what I want to do ?
onLongClick():
Returns
true if the callback consumed the long click, false otherwise.
So, if you return true the onclick won't be executed.

Cancel onListItemClick() if onCreateContextMenu() Fails

I have a basic ListActivity that supports context menus via onCreateContextMenu() and onContextItemSelected(). If either of these methods fail and the context menu is not generated, the current default functionality seems to be to fire off onListItemClick(). TO me, if a user intentionally holds down their finger to get to the context menu, only to then have the item open, is very confusing and could lead them to simply abandoning this gesture in your app if it happens.
What I'd like to do is on failure fire off a Toast with a helpful message, then cancel the onListItemClick so that the list item doesn't open. I have the Toast working, but trying to figure out if it's possible to cancel the click action from inside on of onCreateContextMenu() or onContextItemSelected() where the error will occur.
Thanks!
So I have a solution to this that I am using and it seems to work fine. I created a boolean field, mIgnoreClick, and set that to false in onCreate(). Then in onCreateContextMenu(), if an error occurs generating the context menu, I set mIgnoreClick to true and send a Toast to the user alerting them that this functionality is currently unavailable. Finally, in onListItemClick(), I check the state of mIgnoreClick; if false, the item is displayed, if true, nothing is done and mIgnoreClick is set back to false so that the user can click on listitems and have them open as needed.
Thus, if the menu wasn't generated properly, I do nothing; they never intended to open the item, so this behavior meets my needs.
Paul

Categories

Resources