Eclipse Android Layout Text

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

MODUL 6

LAYOUT OBJEK
 Desain Buat project baru berikut ini
- File
- New
- Other
- Android Project
- Project Name : [Nama Anda] Contoh : layout
- Next
-  Android 2.2
- Next
- Aplication Name : [Nama Anda] contoh : layout
- Package Name : [nama anda].layout
contoh : hendryan.layout
- Finish
 Desain Form seperti gambar berikut pada main.xml:

Objek Keterangan
TextView Text:Nilai A, id="@+id/textView1"
EditView id="@+id/tvnilaiA"
TextView Text:Nilai B, id="@+id/textView2"
EditView id="@+id/tvnilaiB "
Button Text:Tambah, id="@+id/tambah"
Button Text:Kurang, id="@+id/kurang"
Button Text:Kali, id="@+id/kali"
Button Text:Bagi, id="@+id/bagi"
TextView Text:Hasil, id="@+id/textView3"
EditView id="@+id/tvhasil "

 Perbaiki perintah yang terdapat pada main.xml menjadi seperti berikut ini:

<?xml version="1.0" encoding="utf-8"?>


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

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nilai A" />
<EditText
android:id="@+id/tvnilaiA"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nilai B" />
<EditText
android:id="@+id/tvnilaiB"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/tambah"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tambah"
android:onClick="tambahClick"/>
<Button
android:id="@+id/kurang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.03"
android:text="Kurang"
android:onClick="kurangClick"/>
<Button
android:id="@+id/kali"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.08"
android:text="Kali"
android:onClick="kaliClick"/>
<Button
android:id="@+id/bagi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:text="Bagi"
android:onClick="bagiClick"/>
</LinearLayout>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hasil" />
<EditText
android:id="@+id/tvhasil"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

 Perbaiki perintah yang terdapat pada LayoutActivity.java

package hendryan.layout;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class LayoutActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void tambahClick (View v){
EditText p = (EditText)findViewById(R.id.tvnilaiA);
EditText l = (EditText)findViewById(R.id.tvnilaiB);
Double A = Double.valueOf(p.getText().toString());
Double B = Double.valueOf(l.getText().toString());
Double hasil = A + B;
TextView Luas = (TextView)findViewById(R.id.tvhasil);
Luas.setText(hasil.toString());
}
public void kurangClick (View v){
EditText p = (EditText)findViewById(R.id.tvnilaiA);
EditText l = (EditText)findViewById(R.id.tvnilaiB);
Double A = Double.valueOf(p.getText().toString());
Double B = Double.valueOf(l.getText().toString());
Double hasil = A - B;
TextView Luas = (TextView)findViewById(R.id.tvhasil);
Luas.setText(hasil.toString());
}
public void kaliClick (View v){
EditText p = (EditText)findViewById(R.id.tvnilaiA);
EditText l = (EditText)findViewById(R.id.tvnilaiB);
Double A = Double.valueOf(p.getText().toString());
Double B = Double.valueOf(l.getText().toString());
Double hasil = A * B;
TextView Luas = (TextView)findViewById(R.id.tvhasil);
Luas.setText(hasil.toString());
}
public void bagiClick (View v){
EditText p = (EditText)findViewById(R.id.tvnilaiA);
EditText l = (EditText)findViewById(R.id.tvnilaiB);
Double A = Double.valueOf(p.getText().toString());
Double B = Double.valueOf(l.getText().toString());
Double hasil = A / B;
TextView Luas = (TextView)findViewById(R.id.tvhasil);
Luas.setText(hasil.toString());
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy