I did implement a gridview having Imageviews as its items and onClick on any of these items, a custom dialog box pops up to give a brief description of the image as seen here.
In the dialog box, there's just one button which closes the dialog box on click. However, I was wondering how the code and login would be if I were to add a second button to the dialog box and speak out the image name on click on that second button.
Thanks in advance! :-)
you should do this
in your adapter of your list view set the content description of your imageview and on the click of your second button
use imageview.getContentDescription ----this returns you a charsequence so speak it using android TextToSpeech engine using the speak method in it...
like this
TextToSpeech tts=new TextToSpeech(this,this) //first for context and other for the onInitListener
now use the speak method..
tts.speak
Related
I am preparing a login dialog that can change to a register dialog.
It has a custom view and contains a clickable text view that I use to switch between the register display and login display.
When a user clicks it I change the title of the dialog and I display or vanish the input box for retyping the password.
However, I can't change the text or the OnClick function of the positive button.
the setPositiveButton method only exists for DialogBuilder but not for the dialog itself.
Do I have to rebuild the entire dialog or is there a way to change the button "on the fly"?
After you have created your dialog, you can access the buttons with help of this:
dialog.getButton(AlertDialog.BUTTON1) //BUTTON1 is positive button
With this you can modify the text of the button.
I would like to ask how to set a layout such that when a user presses a button in a row, a popup menu appears next to the button, letting the user choose to edit or delete that row?
also, i would like to ask how can i make a layout such that when the user presses the add button, a popup dialog similar to the AlertDialog pops-up? Inside the pop-up dialog the users can input 4 edittexts?
Can the AlertDialog be amended to accept user input, i.e. EditTexts?
Is there any code for reference?
One easy way to have an edit/delete button is to already have the button in your layout but set its visibility to View.INVISIBLE invisible. When the other button is pressed, just change the edit/delete button's visibility to View.VISIBLE.
For the custom dialog, use AlertDialog.Builder and use the setView() to use your custom layout inside the dialog.
http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setView(android.view.View)
Here's a blog post with some sample code:
http://android-coding.blogspot.com/2011/05/create-custom-dialog-using.html
I have an app where the user presses a button and a custom spinner is popped so that the user can choose between nine colors. I want the spinner to be dismissed, when the user touches the background (every place on the sreen except from the spinner). Is this possible?
I tried to add an onTouchListener on the image that covers the background and call
dialog.dismiss();
but it does not work.
My spinner is custom Spinner, set in an xml file and popped with:
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.colorchooser);
Thank you in advance
First of all you should be able to add
dialog.setCanceledOnTouchOutside(true);
to accomplish what you want.
But the dismiss() method should also be working, I would guess that the place your are calling dialog.dismiss() is not reachable at the current moment.
I have to call search dialog when I press a button into the activity or when I press an ImageView, not with the hardware button like in this post:
How can I call search dialog on button click in android?
Please if you have the code or a tutorial, thanks a lot.
In the docs for the search dialog under "Invoking the search dialog"
...However, some devices do not include a dedicated SEARCH button, so you should not assume that it's always available. When using the search dialog, you must always provide another search button in your UI that activates the search dialog by calling onSearchRequested()...
So you should be able to put onSearchRequested(); inside your click listener to when the image is pressed this method call should launch the search dialog for you.
I have an onclick listener for a button. Is there any way when I click the button, make the text change color until my new activity is brought up?
You can use setTextColor() on a button, too, as it extends a TextView (you can Ctrl+F on that page for "setTextColor()" to find the reference, it's under "Inherited XML Attributes"). So when the button is pressed you would use button.setTextColor(newColorInt); and when the loading is done button.setTextColor(oldColorInt);