Anda di halaman 1dari 22

PEMROGRAMAN MOBILE

TUGAS PRAKTIKUM 3
WIDGET

=
=
OLEH:
DANA EKA IRWANDA

NIM : 1431143006

==

JURUSAN TEKNOLOGI INFORMASI


PROGRAM STUDI MANAJEMEN INFORMATIKA
POLITEKNIK NEGERI MALANG
2015

1. Widget RadioButton / RadioGroup


- Project Name : RadioGrup
- Application Name : MainActivity
- Source Code Activity_main.xml
- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/andro
id"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="radio button 1"
android:id="@+id/radioButton" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="radio button 2"
android:layout_below="@+id/radioButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/radioButton2" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="radio button 3"
android:layout_below="@+id/radioButton2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

Hasil Percobaan 1 Radio Button

2. Widget ListView
- Project Name : ListView
- Application Name : MainActivity.java
- Source Code MainActivity.java
- package com.example.hudart.listview;
import
import
import
import
import
import
import
import
import

android.os.Bundle;
android.support.v7.app.AppCompatActivity;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.widget.AdapterView;
android.widget.ArrayAdapter;
android.widget.ListView;
android.widget.Toast;

public class MainActivityextends AppCompatActivity {


private ListViewlvitem;
private String[] footballClubs= new String[]{
"AC Milan","Arsenal","Real Madrid",
"Bayern Muenchen","Manchester United","Ajax Amsterdam",
"Barcelona"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvitem= (ListView)findViewById(R.id.lv_item);
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_list_item_1,
android.R.id.text1, footballClubs);
lvitem.setAdapter(adapter);
lvitem.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,
intposition, long id) {
Toast.makeText(MainActivity.this, "KamuKlik :
"+footballClubs[position], Toast.LENGTH_LONG).show();
}
});
}
@Override
public booleanonCreateOptionsMenu(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 booleanonOptionsItemSelected(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.
intid = item.getItemId();
//noinspectionSimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

- Source Code Activity_main.xml


- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/andro
id"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:id="@+id/lv_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="121dp" />
</RelativeLayout>

Hasil Percobaan 2 ListView

3. Spinner / ComboList
Project Name : Spinner
- Application Name : MainActivity.java
- Source Code MainActivity.java
- package com.example.hudart.combolist;
import
import
import
import
import
import

android.support.v7.app.AppCompatActivity;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.widget.ArrayAdapter;
android.widget.Spinner;

import java.util.ArrayList;
import java.util.List;
public class MainActivityextends AppCompatActivity {
Spinner sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp= (Spinner) findViewById(R.id.spinner);
//untukmembuat list kota, ataubisamenggunakan String[]
List<String> item = new ArrayList<String>();
item.add("Blitar");
item.add("Malang");
item.add("Kediri");
item.add("Jakarta");
//untukmembuat adapter list kota
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_spinner_dropdown_item,item);
//untukmenentukan model adapter nya
adapter.setDropDownViewResource(android.R.layout.simple_spinner_drop
down_item);
//menerapkan adapter pada spinner sp
sp.setAdapter(adapter);
}
@Override
public booleanonCreateOptionsMenu(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 booleanonOptionsItemSelected(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.
intid = item.getItemId();
//noinspectionSimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

- Source Code Activity_main.xml


- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/andro
id"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
</RelativeLayout>

Hasil Percobaan 3 Spinner

4. Input Type
- Project Name : InputType
- Application Name : MainActivity
- Source Code MainActivity.java
- package com.example.hudart.inputtype;
import
import
import
import

android.support.v7.app.AppCompatActivity;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;

public class MainActivityextends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public booleanonCreateOptionsMenu(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 booleanonOptionsItemSelected(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.
intid = item.getItemId();
//noinspectionSimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

- Source Code Activity_main.xml


- <TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TableRow>
<TextViewandroid:text="Email:" />
<EditText />
</TableRow>
<TableRow>
<TextViewandroid:text="Umur:" />
<EditTextandroid:inputType="number" />
</TableRow>
<TableRow>
<TextViewandroid:text="TanggalLahir:" />
<EditTextandroid:inputType="date" />
</TableRow>
<TableRow>
<TextViewandroid:text="Alamat:" />
<EditText
android:inputType="text"
android:minLines="3"
android:gravity="top" />
</TableRow>
</TableLayout>

Hasil Percobaan 4 Input Type

5. MessageBox
- Project Name : MessageBox
- Application Name : MainActivity
- Source Code MainActivity.java
- package com.example.hudart.messagebox;
import
import
import
import
import
import
import
import
import

android.app.AlertDialog;
android.content.DialogInterface;
android.os.Bundle;
android.support.v7.app.AppCompatActivity;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.widget.Button;
android.widget.Toast;

public class MainActivityextends AppCompatActivityimplements


View.OnClickListener{
Button alert;
Button toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alert = (Button) findViewById(R.id.alert);
alert.setOnClickListener(this);
toast = (Button) findViewById(R.id.toast);
toast.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view == alert) {
new AlertDialog.Builder(this)
.setTitle("judulpesan")
.setMessage("iniadalahisi message box")
.setNeutralButton("close", new
DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, intsumthin) {
}
})
.show();
} else {
Toast.makeText(this, "Iniisi message box toast",
Toast.LENGTH_SHORT).show();
}
}
@Override
public booleanonCreateOptionsMenu(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 booleanonOptionsItemSelected(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.
intid = item.getItemId();
//noinspectionSimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

- Source Code Activity_main.xml


- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/andro
id"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextViewandroid:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

Hasil Percobaan 5 MessageBox

6. TypeFace
- Project Name : TypeFace
- Application Name : MainActivity
- Download Font Mistral dan Buat Folder assets
- Masukkan pada project android seperti gambar dibawah ini

- Source Code MainActivity.java


- package com.example.hudart.messagebox;
import
import
import
import
import
import
import
import
import

android.app.AlertDialog;
android.content.DialogInterface;
android.os.Bundle;
android.support.v7.app.AppCompatActivity;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.widget.Button;
android.widget.Toast;

public class MainActivityextends AppCompatActivityimplements


View.OnClickListener{
Button alert;
Button toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alert = (Button) findViewById(R.id.alert);
alert.setOnClickListener(this);
toast = (Button) findViewById(R.id.toast);
toast.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view == alert) {
new AlertDialog.Builder(this)
.setTitle("judulpesan")
.setMessage("iniadalahisi message box")
.setNeutralButton("close", new
DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, intsumthin) {
}
})

.show();
} else {
Toast.makeText(this, "Iniisi message box toast",
Toast.LENGTH_SHORT).show();
}
}
@Override
public booleanonCreateOptionsMenu(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 booleanonOptionsItemSelected(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.
intid = item.getItemId();
//noinspectionSimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Source Code Activity_main.xml

<TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TableRow>
<TextView
android:text="sans:"
android:layout_marginRight="4px"
android:textSize="20sp" />
<TextView
android:id="@+id/sans"
android:text="Dana Irwanda"
android:typeface="sans"
android:textSize="20sp" />

</TableRow>
<TableRow>
<TextView
android:text="serif:"
android:layout_marginRight="4px"
android:textSize="20sp" />
<TextView
android:id="@+id/serif"
android:text="Dana Irwanda"
android:typeface="serif"
android:textSize="20sp"/>
</TableRow>
<TableRow>
<TextView
android:text="monospace:"
android:layout_marginRight="4px"
android:textSize="20sp" />
<TextView
android:id="@+id/monospace"
android:text="Dana Irwanda"
android:typeface="monospace"
android:textSize="20sp" />
</TableRow>
<TableRow>
<TextView
android:text="Mistral"
android:layout_marginRight="4px"
android:textSize="20sp" />
<TextView
android:id="@+id/custom"
android:text="Dana Irwanda"
android:textSize="20sp" />
</TableRow>
</TableLayout>

Hasil Percobaan 6 TypeFace

LATIHAN
1. Buatlah aplikasi dengan menggunakan gabungan widget yang ada diatas kemudian cantumkan
perintahnya dan hasil tampilannya.
- Source Code MainActivity.java
- <TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="@+id/custom"
android:text="Data Diri : Dana EkaIrwanda"
android:textSize="20sp" />

<TableRow>
<TextViewandroid:text="Email : "/>
<EditTextandroid:textSize="25px" />
</TableRow>
<TableRow>
<TextViewandroid:text="Umur:" />
<EditTextandroid:inputType="number"
</TableRow>

android:textSize="25px" />

<TableRow>
<TextViewandroid:text="TanggalLahir:" />
<EditTextandroid:inputType="date"
android:textSize="25px"/>
</TableRow>
<TableRow>
<TextViewandroid:text="JenisKelamin :" />
<RadioGroup
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25px"
android:text="Laki-laki"/>
<RadioButton
android:layout_width="wrap_content"
android:textSize="25px"
android:layout_height="wrap_content"
android:text="Perempuan"/>
</RadioGroup>
</TableRow>

<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25px"
android:id="@+id/spinner"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
></Spinner>
<Button
android:layout_width="50px"
android:layout_height="70px"
android:textSize="25px"
android:text="MessageBox/Alert"
android:id="@+id/alert" />
<Button
android:id="@+id/toast"
android:text="Message Toast"
android:layout_width="50px"
android:textSize="25px"
android:layout_height="70px" />
<TextViewandroid:text="Hobi :" />
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="25px"
android:id="@+id/lv_item"
android:cacheColorHint="@android:color/transparent"
>
</ListView>

</TableLayout>

- Source Code Activity_main.xml


- package com.example.hudart.typeface;
import
import
import
import
import
import

android.graphics.Typeface;
android.os.Bundle;
android.support.v7.app.AppCompatActivity;
android.view.Menu;
android.view.MenuItem;
android.widget.TextView;

public class MainActivityextends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextViewtv=(TextView) findViewById(R.id.custom);
Typeface
face= Typeface.createFromAsset(getAssets(),
"Mistral.ttf");
tv.setTypeface(face);
}
@Override
public booleanonCreateOptionsMenu(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 booleanonOptionsItemSelected(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.
intid = item.getItemId();
//noinspectionSimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Hasil Percobaan