I have a Gallery that I've set up with this type of thing. Works great, except on initial load. The initial gallery item isn't "selected" according to the drawable. Sliding the gallery back and forth makes it work fine and going back to the first has it selected correctly. Any ideas?
What do you mean by "selected"? Gallery only draws a "selector" indicator if the view is focused, which usually only happens when you're using non-touch input (e.g., arrow keys, jogball, etc). If you touch/swipe to move around in it, you enter "touch mode", which usually does not draw a "selector". The same is true of ListView. Read this for more information on what Touch Mode is, and why it's important to understand the difference.
I ended up using this as a guide. I didn't get exactly what I wanted, but this was useful.
Related
I'm using a GridView following this tutorial.
In my app, each image in the grid acts as a button that takes the user to another screen. That's all fine and dandy.
What I'm having trouble with is finding some way to darken the image once a user clicks down, and then lighten it again when the user releases it. onItemClickListener doesn't have an onItemDownClick function built in. What would be the best/most pain free way to create this functionality, or a similar function?
instead of CLICK use the TOUCH events (which have down and up and a lot of other stuff) and for the darkening and lightening I would use a semi opaque colored box that you show/hide depending on the situation.
Good day to all!
I'm trying to implement a voice over for Android (like iPhone), but a specific application (not the entire operating system)
Imagine a screen with six buttons, so they occupy the entire activity, distributed equally in size.
When I "walk" with my finger on the screen, I want to give focus to the button and capture the event when the button has focus and let the focus as well.
Conclusion: As I flick on the screen and if it is over a button, the focus button. if I continue to drag the finger, give the focus to another button without taking your finger off the screen.
Can anyone help me? Sorry for bad English.
I don't think you can use the Android Button class for this, but instead do a custom view, draw six rectangles, and write an onTouchEvent method that determines what sound to play based on where the user's finger is. See the Sudokuv4 example at http://pragprog.com/book/eband3/hello-android for some code you can use.
Well you have to know positions of buttons. You can use basic view functions to get positions (getLeft(), and so on...)
After that you have to implment onTouchListner for Activity. Within you have to check where Event.x and Event.y pointers are and set foucs to specified view. After pointers move from specified view you set focus to false.
following link has some button at the top like :: "DISEASES" , "FOOD & NUTRITION" , "PHYSICAL ACTIVITY"
http://www.bam.gov/sub_yourbody/yourbody_smilestyle.html
when you focus it it will grow and remove from it it will small
so question is how can i do it?
What you have to do is set selector for your button as shown in my previous answer.
And depending on your requirement set drawable larger than the normal ones for that particular state , that will create the same effect
You have to understand that there's a huge difference between a mouse as a pointing device and your finger. A mouse can easily hover across these buttons to give you the effect, but it doesn't work as well with a finger, as you'd need to slide your finger across the buttons to get the effect - and who slides their finger across buttons instead of just pressing them?
Anyway, I suppose you could create an OnTouchListener for your Buttons, and perhaps throw in some animations to get the effects.
But - like I said - I don't see a reason to do this. It seems utterly unnecessary.
I am trying to make an application for android that is based on IPAD app. I want to keep the same look to the app, but I am not a very good designer. So I was wondering if it was possible to for me to crop say the entire header and then have an invisible button or something on top of portions of it. so the design would become a little bit easier. Also if that is possible how would I get the what ever the event item is going to be to overlap with a portion of the image if it has stranger orientation. (I think I could fake this by just moving it closest orientation and extending the size untill it fits, but it would be nice to find a better way.)
How would I go about that?
I tried making the button invisible, but that did not seem to work.
Thanks in advance
I got lost on your description. But if you want to make a button invisible, calling setVisibility(View.INVISIBLE); will not work, because it will not receive click events. You may want to set its color to transparent instead. try using:
button.setBackgroundColor(Color.TRANSPARENT);
I have a clickable TextView with a drawable as its background. I'm looking for the right way to implement a down-state drawable so the background changes when the user presses down. I have been able to almost perfectly replicate this behavior by listening for MotionEvents and changing the background when the user is pressing down.. The only thing that doesn't match up with system-wide down state behavior here is that if the user keeps holding down and moves their finger off the button, the state remains down until they release their finger from the screen... whereas in Maps overlays or Buttons or ListViews or anything else the state immediately goes back to off when the finger moves from the object.
I know there must be some proper way to go about doing this... A nudge in the right direction would be great!
Thanks,
Nick
You need to use a Selector for the background. I'm not sure if there is an official example of how to use Selectors, but I found this site that seems to have a pretty good example:
http://www.craiget.com/2009/03/restyling-android-imagebuttons/
That should get you on the right track.
Edit: Apparently that first link is down, until/unless it comes back here is another example: http://www.mkyong.com/android/android-imagebutton-selector-example/