Android - Play Sound on Button Click - android

I have been following an online tutorial on how to play sound on button click. I am getting no errors with my Java code which leads me to believe that the code is correct.
However, they did not provide a tutorial on what the xml should read. So I left it as it is but when the Activity loads nothing is occuring and I'm left with the Hello World Template.
Could somebody advise me how to get this code to run in the view and if so how. If not could they maybe provide me with an alternate option.

Currently in your XML you have a TextView, you should add a Button (actually you can just change TextView to Button in this case). After that you need to either add
android:onClick="onClick"
under the button.
Or you can use a onClickListener for the button.

Related

Android recording voice when a button is clicked

I have a 'Play'button set up in an XML layout file,
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="play"
android:onClick="playButton"
/>
and I want to make it so that when I click on the button, an action dialog shows in which there are two buttons that say 'Play' and 'Stop'.
When I click on the Play button I want the app to record whatever the user is saying to the microphone and when the 'Stop' button is pressed, save that mp3 into resources.
How can I make this? I'm right now really confused because my
and yes, I've seen the Android documentation & sample codes on Media Recorder and I still don't get it...
try to see this resource on Github android-MediaRecorder
make something similar that you dear, but use camera of the devices. By the way you can start from here and make some adjustment
By the way , you can find more project like this, ad example this AndroidAudioRecorder
that are already did.
Maybe this can be help you
Have a nice work!

Call android activity after pin code screen

I am following this tutorial on creating basic pin code screens: http://lomza.totem-soft.com/pin-input-view-in-android/
I'm just stucked because I don't know how I would call another activity after the Pin code screen has been shown. I'm thinking that there's a button but I don't know where in the code exactly I would be putting the listener.
I just started studying android development so I'm not really familiar with it. Any response would be appreciated.
#Senya is correct, the tutorial is pretty much basic stuff, there's no Button provided and you should add one yourself if you really want one.
However the whole point of a pin is quick access for the user so it is better if you don't provide a separate done button but just listen for the keys in onKey() method and verify the pin as correct, and you can launch your Activity if it is.
In the tutorial just an example of PIN View without extra logic. You can add Button to layout or set listener to EditText for EditorInfo.IME_ACTION_DONE if you want.
Update: in this case listener should be added to the last EditText.

What is good way to backtrack a function in your Android app (like a button) to the code that implements it?

I have a project that I did not develop but am trying to fix bugs in. There's a button that I press and then a bug occurs. I want to find out where in the code this button is implemented but its hard to trace it since there are so many classes and layout files. Usually, if there's text associated with the button, then I find the string in my strings.xml file and work my way back. Unfortunately, this button doesn't have any text associated with it.
Hey just connect your actual android phone and run the app on it and also open logcat, when you will click that button logcat should hopefully display all the errors and you can go to the function.
Try this and comment me back if it works
This is a unconvential method, but I used it in the beginning aswell. In Android Studio press CTRL + H to open the Find in Path dialog. This will search the whole project.
For a Button you might want to search e.g. setOnClickListener, Button etc. and navigate it down by this approach. This method will also find dynamically created Views in case it's not in the layout.xml

Kinda new to programming and got some questions

i just signed up to this site, and im kinda new to programming, so im gonna need help,i downloaded android studio and i've got a couple of questions:
1. sometimes i cant move a button or a textview freely wherever i want, what may be the problem? (not sure how to divide the layouts well btw)
2. how to make a button transparent?(I made my own background with designed sign in button, now i wanna place a button above that sign in button pic that i made and make it transparent)
3.i have a project at school to make an app with web service, i have to add a working sign up and sign in button for anyone who'd like to sign, if you have any tips or video tutorials i can use that'd be awesome!
Sorry for long post, i really wanna master programming and making this new step
Thanks a ton :D
In code:
Button yourButton = (Button) findViewById(R.id.your_button);
yourButton.setBackgroundColor(getResources().getColor(android.R.color.transparent));
In xml:
<Button
...
android:background="#android:color/transparent"
/>
The problem on not being able to move the buttons,textviews,etc, was probably because of the parent layout you are using.Are you using Relative Layout?Relative layout positions widgets according to the previous widget.For example you drag a textview in the middle of the screen,then you add another below it. The next time you move any of these two, the other would move according to the distance you previously put it with the other widget.Try converting it to a Linear layout(can be vertial or horizontal), where your widgets are aligned horizontally or vertically.Just a tip, you can put a layout inside another layout,and this personally makes it easier for me to position things :) hope this helped.

How to highlight clicks in app widget?

I have an app widget which runs neatly. However, I am unable to highlight a click on a linked item. I've seen it in the standard app widgets like 'Music' and 'Power Control', for instance. Moreover, I've also been studying the Music app widget's source at album_appwidget.xml. The only thing I could think of is the LinearLayout defined at lines 23-35 which states
android:clickable="true"
Unfortunately, this does not work for me. So does anyone have a hint on how to highlight a click on an app widget? I've tried the LinearLayout, TextView and Button. None of them displayed a border as a highlight.
Thanks in advance,
Steff
you need to create images for those states like focussed state, pressed etc like in a button and define them in your background.
Try looking at the custom buttons where its explained how to accomplish the task thats similar to your needs.
http://www.gersic.com/blog.php?id=56.
if you want to look more and add more states you may ge better idea if you look at the android source code for buttons where they have images for each state of the button and every other widget.

Categories

Resources