728x90 AdSpace

Thursday, April 25, 2019

Membuat Aplikasi Android Cek Harga Tiket Pesawat Menggunakan Eclipse

Sebagai pemenuhan tugas UTS semester Genap kali ini membuat tugas Aplikasi android menggunakan eclipse, yang mana aplikasi yang saya buat berjudul aplikasi android cek harga tiket pesawat.
Untuk membuatnya pertama buka Eclipse -> pilih new project android -> sesuaikan nama yang di inginkan, setelah lembar kerja dibuat selanjutnya memilih tools yang akan dipakai diantaranya : TextView, Plain Text, Spinner, Radio Button dan Button.

Halaman Login


Xml grapic dari menu login

<RelativeLayout xmlns: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"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/Txtlogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="74dp"
        android:text="MENU LOGIN"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textpass"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="51dp"
        android:onClick="Login"
        android:text="Login" />

    <EditText
        android:id="@+id/textpass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/Txtpassword"
        android:layout_alignLeft="@+id/Txtlogin"
        android:ems="10"
        android:inputType="textPassword" />

    <EditText
        android:id="@+id/textid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/Txtuser"
        android:layout_alignRight="@+id/textpass"
        android:ems="10"
        android:inputType="textPersonName" />

    <TextView
        android:id="@+id/Txtuser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textpass"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="28dp"
        android:layout_marginLeft="16dp"
        android:text="User"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/Txtpassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/Txtuser"
        android:layout_centerVertical="true"
        android:text="Password"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

Java dari menu login

package com.utstiket;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
EditText user;
EditText password;
Button login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        user = (EditText) findViewById(R.id.textid);
        password = (EditText) findViewById(R.id.textpass);  
    }
    
public void Login (View view){
String nama = user.getText().toString();
String pass = password.getText().toString();
if(nama.equals("dedi")&& pass.equals("123")){
Intent i= new Intent (this, MenuTiket.class);
startActivityForResult (i, 0);
}
}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
}

Tab Host

Xml grapic dari tabhost
<RelativeLayout xmlns: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"
    tools:context=".MenuTiket" >
    
     <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</RelativeLayout>

Java dari Tabhost

package com.utstiket;



import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;

public class MenuTiket extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_tiket);
Intent intent;
        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        
        intent =new Intent().setClass(this, MenuTiket.class);
        spec = getTabHost().newTabSpec("CekHarga").setIndicator("CekHarga").setContent(intent);
        tabHost.addTab(spec);
        
        intent =new Intent().setClass(this, Traveloka.class);
        spec = getTabHost().newTabSpec("Garuda").setIndicator("Garuda").setContent(intent);
        tabHost.addTab(spec);
        
        intent =new Intent().setClass(this, About.class);
        spec = getTabHost().newTabSpec("LionAir").setIndicator("LionAir").setContent(intent);
        tabHost.addTab(spec);
        
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_menu_tiket, menu);
return true;
}

}


Menu Cek Tiket



xml grapic dari menu cek harga tiket

<RelativeLayout xmlns: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"
    tools:context=".MenuTiket" >
    
     <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</RelativeLayout>

Java dari menu tiket

package com.utstiket;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Spinner;
import java.util.ArrayList;
import java.util.List;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import android.widget.ArrayAdapter;


public class TiketPesawat extends Activity {
    /** Called when the activity is first created. */
 int hargatiket,biayakelas,biayaservicemeal,biayaservicedrink;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tiket_pesawat);
        addItemsOnSpinner1();
    }
    private void addItemsOnSpinner1() {
  // TODO Auto-generated method stub
     Spinner Tjn = (Spinner) findViewById(R.id.texttujuan);
  List<String> list = new ArrayList<String>();
  list.add("Jakarta");
  list.add("Batam");
  list.add("Padang");
  
  ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_spinner_item, list);
  dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  Tjn.setAdapter(dataAdapter); 
 }
    
 public void hitungbiaya(View v){
     EditText nama = (EditText)findViewById(R.id.textnama);
     String Nama = nama.getText().toString();
     
     Spinner Tjn = (Spinner) findViewById(R.id.texttujuan);
     String Tujuan = Tjn.getSelectedItem().toString();
     if ("Jakarta".equals(Tujuan))
     {
      hargatiket= 750000;
      }
     else if("Batam".equals(Tujuan))
     {
      hargatiket= 450000;
     }
     else if("Padang".equals(Tujuan))
     {
      hargatiket= 350000;
     }
   
       
       int totalbiaya = hargatiket+biayakelas+biayaservicemeal+biayaservicedrink;
       
       NumberFormat numberFormat  = new DecimalFormat("#,###,###");
  String str = numberFormat.format(totalbiaya); 
  
        TextView totalharga = (TextView)findViewById(R.id.cetak);
       totalharga.setText("Harga Tiket Bpk/Ibu. "+Nama.toString() + " Rp."+ str);
    }

}




  • Blogger Comments
  • Facebook Comments

0 komentar:

Post a Comment

Item Reviewed: Membuat Aplikasi Android Cek Harga Tiket Pesawat Menggunakan Eclipse Rating: 5 Reviewed By: savictif media