help with buttons

  • Replies:8
dj nate
  • Forum posts: 6

Apr 9, 2017, 6:42:17 PM via Website

hi

im very new, and im trying to put buttons on my app

in android studio, i click the button thing, i drag and drop them, place them correctly... they look good
when i build apk and install on my phone, all my buttons disappear only one remains top left (its like if they would all be at the same location....) but in the text view i see the x and y positions are different for each buttons...

what am i missing? does it have to do with the screen resolution or something?
i just want to put buttons on my app...

if someone could give me hint would be greatly appreciated

regards,
nate

Reply
Dev Lt
  • Forum posts: 54

Apr 12, 2017, 8:17:54 PM via Website

post your layout xml file, then we would see what's wrong

Reply
dj nate
  • Forum posts: 6

Apr 12, 2017, 9:37:12 PM via Website

the problem was that i was using constraint layout i dont know why its loading that layout by default, i replaced for Absolutelayout and button positions are ok now

now what i would like is to have mediaplayer.release called after each song is done playing... i dont know how to call mediaplayer.release

if you can give me a clue

thanks
nate

(ill post my activity main xml and java later cause im at work right now)

Reply
dj nate
  • Forum posts: 6

Apr 13, 2017, 6:31:35 PM via Website

here is activity_main.xml


xmlns:app="****"
xmlns:tools="****"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.thepiratebay.keven.MainActivity"
android:background="@drawable/background">

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="51dp"
    android:layout_y="47dp"
    android:onClick="sound1"
    android:text="bonnefete1" />

and here is mainactivity.java:

package org.thepiratebay.keven;

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {
MediaPlayer sound1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    sound1 = MediaPlayer.create(this, R.raw.a1toutunmot);
}

public void sound1(View view) {
    sound1.start();
}

}

i found someone saying

MediaPlayer mp = MediaPlayer.create(YourActivity.this, R.raw.mysound);
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();

This is the best way I found to play a sound in Android. Hope it helps!

not sure where to fit this code...

anyways any clue will be greatly appreciated

thanks
nate

Reply
dj nate
  • Forum posts: 6

Apr 13, 2017, 8:58:10 PM via Website

basically i want to release mplayer when the sound is finished playing

Reply
Taiduol
  • Forum posts: 11

Apr 14, 2017, 11:29:52 AM via Website

Thanks for your topic

Reply
dj nate
  • Forum posts: 6

Apr 14, 2017, 10:44:55 PM via Website

happy it can help... but im still wondering how to release mediaplayer after a song is done playing

Reply
RjApp Studio
  • Forum posts: 4

Apr 15, 2017, 7:44:02 PM via Website

I think you are right. This one is right solution for this problem.

Reply
dj nate
  • Forum posts: 6

Apr 15, 2017, 8:25:32 PM via Website

where do i put that section?

Reply