1. Listing Program (xml)
android:id="@+id/Button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/uu"
android:gravity="center_vertical"
tools:context=".MenuButton" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="MENU PERHITUNGAN"
android:textAppearance="?android:attr/textAppearanceLarge" />
2. Listing Program (Java)
package com.example.menubutton;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class MenuButton
/** Called when the activity is first created. */
public static final int Exit = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menubutton);
findViewById(R.id.button1).setOnClickListener(this);
findViewById(R.id.button2).setOnClickListener(this);
findViewById(R.id.button3).setOnClickListener(this);
findViewById(R.id.button5).setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()) {
case R.id.button1:
Intent f = new Intent(this, VolumeKubus.class);
startActivity(f);
break;
case R.id.button2:
Intent g = new Intent(this, LuasLingkaran.class);
startActivity(g);
break;
case R.id.button3:
Intent h = new Intent(this, NilaiMahasiswa.class);
startActivity(h);
break;
case R.id.button5:
showDialog(Exit);
break;
}
}
}
Catatan: untuk menambah button buat button baru dengan id yg berbeda dan case yang berbeda.
0 komentar:
Posting Komentar