Kamis, 31 Oktober 2019

Tugas UTS Mobile Programming

UTS Mobile Program Stmik Eresha 06TPLP001


Assalamualakum Wr. Wb

Pada kesempatan kali ini saya akan membuat tugas cara pembuatan aplikasi(ListView) dengan menggunakan Android Studio.


Aplikasi Mobile Informasi Negara Negara Di Asia Tenggara


Deskripsi

Aplikasi Mobile Programming yang saya buat untuk menampilkan informasi tentang negara-negara yang berada di Asia Tenggara






Screenshoot dan Source Code

Menu Login



MainActivity.java

package com.listview;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView username,password;
    Button button;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        username = (TextView) findViewById(R.id.etusername);
        password = (TextView) findViewById(R.id.etpassword);
        button = (Button)   findViewById(R.id.btnlogin);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (username.getText().toString().equals("irsan") && password.getText().toString().equals("12345"))
                {
                    Intent ilogin = new Intent(getApplicationContext(), listview.class);
                    startActivity(ilogin);

                }
                else
                {
                    username.setText("");
                    password.setText("");
                }
            }
        });
    }
}




activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#6969"
    tools:context=".MainActivity">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp">


        <EditText
            android:id="@+id/etusername"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="460dp"
            android:ems="10"
            android:hint="username"
            android:inputType="textPersonName" />

        <Button
            android:id="@+id/btnlogin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="530dp"
            android:text="Login" />

        <EditText
            android:id="@+id/etpassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="485dp"
            android:ems="10"
            android:hint="password"
            android:inputType="textPassword" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="380dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="50dp"
            android:visibility="visible"
            app:srcCompat="@drawable/asiatenggara" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="405dp"
            android:text="WELCOME"
            android:textSize="50sp" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:text="Negara Asia Tenggara"
            android:textSize="40sp" />


    </RelativeLayout>
</RelativeLayout>

Menu Tampilan


listview.java

package com.listview;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.view.View;


public class listview extends AppCompatActivity {

    ListView list;
    String minuman[] = {"kamboja", "bruneidarussalam", "filipina", "vietnam", "laos", "malaysia", "singapura", "Indonesia", "myanmar", "thailand"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);
        list = (ListView) findViewById(R.id.listview);
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, minuman);
        list.setAdapter(adapter);


        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                int item = arg2;
                String itemText = (String) list.getItemAtPosition(arg2);

                if (itemText.equals("kamboja")) {
                    Intent anggurintent = new Intent(arg0.getContext(), kamboja.class);
                    startActivityForResult(anggurintent, 0);

                } else if (itemText.equals("bruneidarussalam")) {
                    Intent Brandyintent = new Intent(arg0.getContext(), bruneidarussalam.class);
                    startActivityForResult(Brandyintent, 0);
                } else if (itemText.equals("filipina")) {
                    Intent Whiskyintent = new Intent(arg0.getContext(), filipina.class);
                    startActivityForResult(Whiskyintent, 0);
                } else if (itemText.equals("vietnam")) {
                    Intent Vodkaintent = new Intent(arg0.getContext(), vietnam.class);
                    startActivityForResult(Vodkaintent, 0);
                }
                else if (itemText.equals("laos")) {
                    Intent Champagneintent = new Intent(arg0.getContext(), laos.class);
                    startActivityForResult(Champagneintent, 0);
                }
                else if (itemText.equals("malaysia")) {
                    Intent jagermeisterintent = new Intent(arg0.getContext(), malaysia.class);
                    startActivityForResult(jagermeisterintent, 0);
                }
                else if (itemText.equals("singapura")) {
                    Intent sakeintent = new Intent(arg0.getContext(), singapura.class);
                    startActivityForResult(sakeintent, 0);
                }
                else if (itemText.equals("Indonesia")) {
                    Intent Rumintent = new Intent(arg0.getContext(), indonesia.class);
                    startActivityForResult(Rumintent, 0);
                }
                else if (itemText.equals("myanmar")) {
                    Intent absintheintent = new Intent(arg0.getContext(), myanmar.class);
                    startActivityForResult(absintheintent, 0);
                }
                else if (itemText.equals("thailand")) {
                    Intent Tuakintent = new Intent(arg0.getContext(), thailand.class);
                    startActivityForResult(Tuakintent, 0);
                }






            }
        });
    }
    }


Activity_listview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".listview">

    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>


Contoh Salah Satu Isi Menu


indonesia.java

package com.listview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class indonesia extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_indonesia);
    }
}


activity_indonesia.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".indonesia">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="300dp"
        android:textStyle="bold"
        android:textSize="30sp"
        android:text="Indonesia"
        />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="380dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="350dp"
        android:textSize="12sp"
        android:layout_centerHorizontal="true"
        android:text="\n    Republik Indonesia (RI) atau Negara Kesatuan Republik Indonesia (NKRI), atau lebih umum disebut Indonesia, adalah negara di Asia Tenggara yang dilintasi garis khatulistiwa dan berada di antara daratan benua Asia dan Australia, serta antara Samudra Pasifik dan Samudra Hindia. Indonesia adalah negara kepulauan terbesar di dunia yang terdiri dari 17.504 pulau. Nama alternatif yang biasa dipakai adalah Nusantara. Dengan populasi Hampir 270.054.853 jiwa pada tahun 2018, Indonesia adalah negara berpenduduk terbesar keempat di dunia dan negara yang berpenduduk Muslim terbesar di dunia, dengan lebih dari 230 juta jiwa."
        />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="232dp"
        android:layout_marginTop="50dp"
        app:srcCompat="@drawable/indonesia" />
</RelativeLayout>





Sekian Tugas Mobile Programming dari saya, Semoga bermanfaat Terimakasih,