4. Selanjutnya, atur fungsi-fungsi yang akan berjalan di layout ini di bagian class javanya, berikut adalah code nya:
package hana.tiwi;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class menu extends Activity implements OnClickListener{
private SoundManager btnSound; ini adalah fungsi sound (ada syntax khusus, jadi jangan dibuat terlebih dahulu)
private SoundManager btnaSound;ini adalah fungsi sound (ada syntax khusus, jadi jangan dibuat terlebih dahulu)
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu); arah layout yang dituju
btnSound = new SoundManager(); fungsi sound
btnSound.initSounds(getBaseContext()); fungsi sound
btnSound.addSound(1, R.raw.bass); arah tujuan sound
btnaSound = new SoundManager();fungsi sound
btnaSound.initSounds(getBaseContext());fungsi sound
btnaSound.addSound(1, R.raw.klik); arah tujuan sound
View e= findViewById(R.id.hijaiyah); pemanggilan id
e.setOnClickListener(this);
View h= findViewById(R.id.harakat);pemanggilan id
h.setOnClickListener(this);
View a= findViewById(R.id.tajwid);pemanggilan id
a.setOnClickListener(this);
View tentang= findViewById(R.id.iqra);pemanggilan id
tentang.setOnClickListener(this);
View ex= findViewById(R.id.keluar);pemanggilan id
ex.setOnClickListener(this);
Toast.makeText(this, "Aplikasi Pengenalan Huruf Hijaiyah, Harakat, Tajwid, & Iqra", Toast.LENGTH_LONG).show();
} tampilan untuk menu keluar
public void onClick(View v){
switch (v.getId()){
case R.id.hijaiyah: fungsi setiap pilihan menu
btnaSound.playSound(1);
Intent level=new Intent(this, hijaiyah1.class);
startActivity(level);
break;
case R.id.harakat: fungsi setiap pilihan menu
btnSound.playSound(1);
Intent x=new Intent(this, harakat.class);
startActivity(x);
break;
case R.id.tajwid:fungsi setiap pilihan menu
btnSound.playSound(1);
Intent n=new Intent(this, tajwid.class);
startActivity(n);
break;
case R.id.iqra:fungsi setiap pilihan menu
btnaSound.playSound(1);
Intent y=new Intent(this, iqra.class);
startActivity(y);
break;
case R.id.keluar:fungsi setiap pilihan menu
btnaSound.playSound(1);
AlertDialog.Builder alertexit = new AlertDialog.Builder(menu.this);
alertexit.setMessage("Anda yakin ingin keluar dari aplikasi ini?")
.setCancelable(false)
.setPositiveButton("YA", new AlertDialog.OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
btnaSound.playSound(1);
System.exit(0);}})
.setNegativeButton("TIDAK",new AlertDialog.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
btnaSound.playSound(1);
dialog.cancel();}
});
AlertDialog a = alertexit.create();
a.setTitle("...");
a.setIcon(R.drawable.bunga4);
a.show();
break;
}}
@Override
public void onBackPressed()
{Toast.makeText(this, "Klik pilihan KELUAR untuk keluar dari APLIKASI ini", Toast.LENGTH_LONG).show();}}
Hasil untuk menu yang saya buat ketika program di run adalah seperti berikut ini:
nb: perhatikan bagian yang berwarna.
Selamat mencoba teman. jika masih ada yang membingungkan tinggalkan pesan dan komentar di bagian posting ini. Terima Kasih telah berkunjung.
0 komentar:
Posting Komentar