TUGAS KULIAH


Cara membuat aplikasi tentang data diri/bioadata serta biodata pendidikan, Jabatan_pekerjaan, dan disertai camera dan login. 
 


A. Cara membuat login
Bukalah android studio lalu open project dan membuat aplikasi loginnya seperti dibawah Masukan codingan activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lusirosalina_161021450352.">

<TextView
android:text="Login Form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="@+id/textView"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="normal|bold" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/username"
android:hint="Username"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="37dp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:layout_below="@+id/username"
android:layout_alignParentLeft="true"
android:id="@+id/password"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Password" />

<Button
android:text="Log In"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/password"
android:layout_centerHorizontal="true"
android:id="@+id/btnLogin" />

</RelativeLayout>
 

Nanti akan muncul seperti ini 




Masukan codingan mainactivity.java  

package com.example.lusirosalina_161021450352;





import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;



import androidx.appcompat.app.AlertDialog;

import androidx.appcompat.app.AppCompatActivity;



public class MainActivity extends AppCompatActivity {



    EditText username, password;

Button btnLogin;



@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);





username = (EditText) findViewById(R.id.username);

password = (EditText) findViewById(R.id.password);

btnLogin = (Button)findViewById(R.id.btnLogin);



btnLogin.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {



                String usernameKey = username.getText().toString();

String passwordKey = password.getText().toString();



                if (usernameKey.equals("admin") && passwordKey.equals("1234")){

//jika login berhasil

Toast.makeText(getApplicationContext(), "LOGIN SUKSES",

Toast.LENGTH_SHORT).show();

Intent intent = new Intent(MainActivity.this, biodata.class);

MainActivity.this.startActivity(intent);

finish();

}else {

//jika login gagal

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

builder.setMessage("Username atau Password Anda salah!")

                            .setNegativeButton("Retry", null).create().show();

}

            }



        });

}

}




Maka akan muncul gambar dibawah ini:





B. Sekarang membuat bioadata serta biodata pendidikan, Jabatan_pekerjaan, dan disertai camera. 


Sekarang kita buat codingan activity_main.xml  

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

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@android:id/tabhost"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<TabWidget

android:id="@android:id/tabs"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_gravity="bottom" />

<FrameLayout

android:id="@android:id/tabcontent"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_gravity="bottom" />

</LinearLayout>

</TabHost>




Gambarnya seperti dibawah:




package com.example.lusirosalina_161021450352;



        import android.os.Bundle;

        import android.app.TabActivity;

        import android.content.Intent;

        import android.widget.TabHost;

@SuppressWarnings("deprecation")

public class MainActivity extends TabActivity {

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

TabHost tabhost = getTabHost();

TabHost.TabSpec spec;

Intent intent;

intent = new Intent().setClass(this, biodata.class);

spec = tabhost.newTabSpec("biodata").setIndicator("Biodata",null).setContent(intent);

tabhost.addTab(spec);

intent = new Intent().setClass(this, biodata_pendidikan.class);

spec = tabhost.newTabSpec("biodata_pendidikan").setIndicator("biodata_pendidikan",null).setContent(intent);

tabhost.addTab(spec);

intent = new Intent().setClass(this, jabatan_pekerjaan.class);

spec = tabhost.newTabSpec("jabatan_pekerjaan").setIndicator("jabatan_Pekerjaan",null).setContent(intent);

tabhost.addTab(spec);

intent = new Intent().setClass(this, camera.class);

spec = tabhost.newTabSpec("camera").setIndicator("Camera",null).setContent(intent);

tabhost.addTab(spec);

}

}


 Gambarnya seperti dibawah:



Sekarang membuat codingan activity_biodata_pendidikan.xml  


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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<ListView

android:id="@android:id/list"

android:layout_width="fill_parent"

android:layout_height="fill_parent" />

</LinearLayout>





Codingan biodata_pendidikan(java):


package com.example.lusirosalina_161021450352;



import android.app.ListActivity;

import android.os.Bundle;

import android.widget.ArrayAdapter;

public class biodata_pendidikan extends ListActivity {

    String [] biodata_pendidikan={"SDN Jipang 05", "MTSN BBS 4", "SMK Ma'arif Btk"};

@Override

public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_biodata_pendidikan);

setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, biodata_pendidikan));

}

}









Sekaranng kita buat codingan  activity_biodata.xml. codingan sama seperti biodata pendidikan, gambarnya dibawah ini:





Codingan biodata.java:


package com.example.lusirosalina_161021450352;

import android.app.ListActivity;

import android.os.Bundle;

import android.widget.ArrayAdapter;

public class biodata extends ListActivity {

    String [] biodata={"Nama : Lusi Rosalina","Alamat : JL.Batu Jimbar No25 Tangerang","NIM : 161021450352", "Hobi : Olahraga"};

@Override

public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_biodata);

setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, biodata));

}

}


Gambaranya seperti di bawah ini:






Sekarang kita buat codiangan activity_jabatan_pekerjaan.xml. sama seperti biodata.xml codingannya. Gambaranya seperti dibawah:




Sekarang codingan jabatan_pekerjaan.java





package com.example.lusirosalina_161021450352;



import android.app.ListActivity;

import android.os.Bundle;

import android.widget.ArrayAdapter;

public class jabatan_pekerjaan extends ListActivity {

    String [] jabatan_pekerjaan={"Sekretaris"};

@Override

public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_jabatan_pekerjaan);

setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, jabatan_pekerjaan));

}

}




Gambaranya seperti dibawah:





Sekearang kita membuat codingan activity_camera.xml




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

<LinearLayout 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"

android:paddingTop="16dp"

android:paddingBottom="16dp"

android:paddingLeft="16dp"

android:paddingRight="16dp"

android:orientation="vertical"

android:weightSum="10"

tools:context=".MainActivity">

<ImageView

android:id="@+id/imageView"

android:layout_weight="9"

android:layout_width="match_parent"

android:layout_height="fill_parent"

/>

<Button

android:id="@+id/buttonCamera"

android:layout_weight="1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@android:color/black"

android:textColor="@android:color/white"

android:text="Kamera"/>

</LinearLayout>




 
Gambaranya seperti dibawah







Sekarang coding camera.java



package com.example.lusirosalina_161021450352;



import androidx.annotation.Nullable;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.graphics.Bitmap;

import android.os.Bundle;

import android.provider.MediaStore;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;

public class camera extends AppCompatActivity {

    ImageView gambarCamera;

Button tombolCamera;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_camera);

tombolCamera=(Button)findViewById(R.id.buttonCamera);

gambarCamera  =(ImageView) findViewById(R.id.imageView);

tombolCamera.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(intent,0);

}

        });

}

@Override

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

super.onActivityResult(requestCode, resultCode, data);

Bitmap bitmap = (Bitmap)data.getExtras().get("data");

gambarCamera.setImageBitmap(bitmap);

}

}





Gambaranya seperti dibawah ini:







Dan yang terakhir jangan lupa buat androidmanifest.xml





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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.tugasuts">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.example.uts.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name="biodata"></activity>

<activity android:name="biodata_pendidikan"></activity>

<activity android:name="jabatan_pekerjaan"></activity>

<activity android:name="camera"></activity>

</application>

</manifest>




Gambarnya seperti dibawah ini:




Berikut hasil dari aplikasinya:  





 



                                                     *SEKIAN DAN TERIMAKASIH*




Komentar