AIDE - IMPLEMENTANDO SOM AO MEU PRIMEIRO PROJETO.

Tags









//
package com.meu.projeto;
import android.content.Intent;
import java.util.Timer;
import java.util.TimerTask;
import android.app.*;
import android.os.*;
import android.widget.*;

public class Splash extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
Toast.makeText(getApplicationContext(),"Aguarde carregando",Toast.LENGTH_SHORT).show();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
finish();
Intent tela1 = new Intent (Splash.this,MainActivity.class);
startActivity(tela1);
}
}, 5000);

    }
}




//
package com.meu.projeto;

import android.app.*;
import android.content.*;

//Novo import MediaPlayer
import android.media.*;

import android.os.*;
import android.view.*;
import android.widget.*;


public class MainActivity extends Activity {
protected static Button bt1,bt2,bt3;

//Novo objeto mediaPlayer
protected static MediaPlayer mediaPlayer = new MediaPlayer();


    @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

bt1 =(Button)findViewById(R.id.bt1);
bt1.setText("Voltar"); //Definindo texto do Botão Programativamente
    bt1.setOnClickListener(new View.OnClickListener(){
    @Override
public void onClick(View b1){
finish();
       Intent tela1 = new Intent (MainActivity.this,
Splash.class);
startActivity(tela1);
Toast.makeText(getApplicationContext(),
"Voltou à tela 1",Toast.LENGTH_SHORT)
.show();
}
   });

bt2 =(Button)findViewById(R.id.bt2);
   bt2.setText("Tocar A");
        bt2.setOnClickListener(new View.OnClickListener(){
        @Override
   public void onClick(View b2){
//onClick Objeto mediaPlayer chamado
mediaPlayer.stop();
mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.soma);

mediaPlayer.start();
Toast.makeText(getApplicationContext(),
"Som - A: " +String.valueOf(getString(R.raw.soma)),Toast.LENGTH_SHORT)
.show();

  }
});

bt3 =(Button)findViewById(R.id.bt3);
   bt3.setText("Tocar B");
        bt3.setOnClickListener(new View.OnClickListener(){
        @Override
   public void onClick(View b3){
mediaPlayer.stop();
mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.somb);

mediaPlayer.start();
Toast.makeText(getApplicationContext(),
"Som - B: " +String.valueOf(getString(R.raw.somb)),Toast.LENGTH_SHORT)
.show();

  }
});
    }
}





//
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
 
</LinearLayout>





//
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:id="@+id/bt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


</LinearLayout>




Obrigado por comentar, volte sempre!
EmoticonEmoticon