You are on page 1of 7

LAPORAN AKHIR PRAKTIKUM

Mata Praktikum

: Interaksi Manusia dan Komputer

Kelas

: 3IA06

Praktikum ke-

:3

Tanggal

: 7 April 2015

Materi

: Image dan Toast

NPM

: 55412973

Nama

: Rama Dian Syah

Ketua Asisten

Nama Asisten

Paraf Asisten

Jumlah Lembar

LABORATORIUM TEKNIK INFORMATIKA


UNIVERSITAS GUNADARMA
2015

Membuat program dengan imageview dan toast


Imageview adalah komponen android untuk menampilkan gambar, Toast adalah pesan text yang
ditampilkan pada android
1. Membuat layout dengan XML
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:replace="android:icon,android:theme"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[DT2S]"
android:textSize="22dp"
android:textColor="#000"
android:padding="12dp"
android:background="#909"/>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">

<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/lector1"/>
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/uniqua"/>
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/lector2"/>>
</TableRow>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit" />
</TableLayout>
Logika
Untuk mengatur layar digunakan Table Layout dan diatur menjadi fill_parent. Untuk
menampilkan

text

digunakan

textview

dan

diatur

menjadi

match_parent

dan

wrap_content.Menampilkan button bergambar digunakan ImageButton. Dan untuk menampilkan


button biasa dengan Button.

2. Untuk kodingan di java.


package com.labti.la3c;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends ActionBarActivity {


Button BT;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BT=(Button)findViewById(R.id.button1);
BT.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

AlertDialog info = new AlertDialog.Builder(MainActivity.this).create();

info.setTitle("Peringatan");
info.setMessage("Anda yakin ingin keluar ?");
//info.setIcon(R.drawable.info);
info.setButton("OK", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {


System.exit(1);
}
});
info.show();
}});}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;

}
return super.onOptionsItemSelected(item);
}}
Logika
Import semua library yang dibutuhkan, deklarasikan button. Untuk menampilkan jendela
pesan/toast dengan alertdialoginfo. Judul jendela dengan info.setTitle.Isi pesan dengan
info.setMessage. Untuk button pada jendela dengan info.setButton.Agar ketika Button exit di klik
akan muncul pesan maka diketikkan sintax System.exit(1);dan info.show();
OUTPUT

You might also like