SlideShare a Scribd company logo
1 of 12
Download to read offline
Basic APP Android Java
persiapan awal membuat xml :
1. activity_main.xml
2. activity_form.xml
3. activity_spinner.xml
4. activity_listview.xml
persiapan membuat java :
1. SpinnerActivity.java
2. FormActivity.java
3. ListviewActivity.java
4. MainActivity.java
coding activity_main.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:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/bToast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button Toast"
tools:ignore="MissingConstraints" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bListView"
android:text="Halaman ListView"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/bspinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Spinner" />
<Button
android:id="@+id/bform"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Page Form" />
<Button
android:id="@+id/bexit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Exit" />
</LinearLayout>
coding MainActivity.java
package com.example.myapplication;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements
OnClickListener {
Button b1, b2, b3, b4, b5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.bToast);
b2 =(Button) findViewById(R.id.bListView);
b3 = (Button) findViewById(R.id.bspinner);
b4 = (Button) findViewById(R.id.bform);
b5 = (Button) findViewById(R.id.bexit);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
b5.setOnClickListener(this);
}
@SuppressLint("ResourceType")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.activity_main, menu);
return true;
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bToast:
Toast.makeText(this, "This is Notification",
Toast.LENGTH_SHORT).show();
break;
case R.id.bListView:
Intent b = new Intent(MainActivity.this,
ListViewActivity.class);
startActivity(b);
break;
case R.id.bform:
Intent f = new Intent(MainActivity.this,
FormActivity.class);
startActivity(f);
break;
case R.id.bspinner:
Intent s = new Intent(MainActivity.this,
SpinnerActivity.class);
startActivity(s);
break;
case R.id.bexit:
// Toast.makeText(this, "Button Exit",
Toast.LENGTH_SHORT).show();
ShowExitDialog();
break;
}
}
private void ShowExitDialog(){
//TODO Auto-generated method stub
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setTitle("Warning");
ad.setMessage("are You sure exit from apps ?");
ad.setPositiveButton("yes", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface,
int which) {
MainActivity.this.finish();
}
});
ad.setNegativeButton("no", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface,
int which) {
//TODO Auto-generated method stub
dialogInterface.dismiss();
}
});
ad.show();
}
}
output :
Coding activity_form.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow
android:id="@+id/tableRows"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Username"
/>
<EditText
android:id="@+id/inUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="username here">
<requestFocus/>
</EditText>
</TableRow>
<TableRow>
<TextView
android:id="@+id/inpassword"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Password"/>
<EditText
android:id="@+id/inPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="password in here"/>
</TableRow>
</TableLayout>
<Button
android:id="@+id/bLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"/>
</LinearLayout>
Coding FormActivity.java
package com.example.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
public class FormActivity extends Activity {
EditText username, pass;
Button blogin;
String user_name= "user";
String password = "user123";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
username = (EditText) findViewById(R.id.inUser);
pass = (EditText) findViewById(R.id.inPass);
blogin = (Button) findViewById(R.id.bLogin);
blogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String u = username.getText().toString();
String p = pass.getText().toString();
checkLogin(u, p);
}
});
}
private void checkLogin(String u, String p) {
if(p.equals(password) && u.equals(user_name)){
Toast.makeText(this, "Login Success",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FormActivity.this,
MainActivity.class);
startActivity(intent);
this.finish();
} else{
Toast.makeText(this, "Login Failled",
Toast.LENGTH_SHORT).show();
}
}
}
output :
Coding activity_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="@+id/idSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Coding SpinnerActivity.java
package com.example.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.annotation.Nullable;
public class SpinnerActivity extends Activity {
Spinner sp;
String[] item ={"nasi goreng","mie ayam","nasi uduk","pecel
lele","Magelangan","Soto ayam"};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spinner);
sp = (Spinner)findViewById(R.id.idSpinner);
ArrayAdapter<String> array_item = new
ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, item);
sp.setAdapter(array_item);
sp.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View
arg1, int arg2, long arg3) {
Toast.makeText(SpinnerActivity.this, "Kamu
Memilih" +
item[arg2],Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
Toast.makeText(SpinnerActivity.this,
"Nothing Selected",
Toast.LENGTH_SHORT).show();
}
});
}
}
output
Coding activity_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/idListView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Coding ListViewActivity.java
package com.example.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.widget.ListView;
import androidx.annotation.Nullable;
import java.util.List;
public class ListViewActivity extends Activity {
ListView lv;
String[] item = {"Nasi Goreng","Mie Goreng", "Mie
Ayam","Magelangan",
"Soto Ayam","Sop Ayam","Ayam Goreng"};
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
lv = (ListView) findViewById(R.id.idListView);
ArrayAdapter<String> array_item = new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, item);
lv.setAdapter(array_item);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View
arg1, int arg2, long arg3) {
Toast.makeText(ListViewActivity.this,
"Kamu Memilih" + item[arg2],
Toast.LENGTH_SHORT).show();
}
});
}
}
output :
@TerimaKasih
Herry Prasetyo
2019

More Related Content

What's hot

Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coveragealertchair8725
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC Newswaggishwedge3973
 
Nightline: Late Evening News - ABC News
Nightline: Late Evening News - ABC NewsNightline: Late Evening News - ABC News
Nightline: Late Evening News - ABC Newsdynamicindividu85
 
Advanced Android gReporter
Advanced Android gReporterAdvanced Android gReporter
Advanced Android gReporternatdefreitas
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC Newswonderfulshuttl70
 
Different types of sticker apps
Different types of sticker appsDifferent types of sticker apps
Different types of sticker appsJelena Krmar
 
Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coverageplantresidence159
 
Desenvolvimento web com Ruby on Rails (extras)
Desenvolvimento web com Ruby on Rails (extras)Desenvolvimento web com Ruby on Rails (extras)
Desenvolvimento web com Ruby on Rails (extras)Joao Lucas Santana
 
Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coverageroastedrecluse128
 
Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coveragecreepypreview6376
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC Newsspiritualvictim28
 
AI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You TypedAI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You TypedMarvin Heng
 
What Would You Do? With John Quinones
What Would You Do? With John QuinonesWhat Would You Do? With John Quinones
What Would You Do? With John Quinonesroastedrecluse128
 
Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coverageunarmedhorse5807
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”apostlion
 
Business News, Personal Finance and Money News
Business News, Personal Finance and Money NewsBusiness News, Personal Finance and Money News
Business News, Personal Finance and Money Newseminentoomph4388
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC Newsmae2savage7
 
Django Class-based views (Slovenian)
Django Class-based views (Slovenian)Django Class-based views (Slovenian)
Django Class-based views (Slovenian)Luka Zakrajšek
 

What's hot (20)

Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coverage
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC News
 
Nightline: Late Evening News - ABC News
Nightline: Late Evening News - ABC NewsNightline: Late Evening News - ABC News
Nightline: Late Evening News - ABC News
 
Advanced Android gReporter
Advanced Android gReporterAdvanced Android gReporter
Advanced Android gReporter
 
U.S. News | National News
U.S. News | National NewsU.S. News | National News
U.S. News | National News
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC News
 
Different types of sticker apps
Different types of sticker appsDifferent types of sticker apps
Different types of sticker apps
 
Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coverage
 
Desenvolvimento web com Ruby on Rails (extras)
Desenvolvimento web com Ruby on Rails (extras)Desenvolvimento web com Ruby on Rails (extras)
Desenvolvimento web com Ruby on Rails (extras)
 
Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coverage
 
Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coverage
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC News
 
AI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You TypedAI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You Typed
 
What Would You Do? With John Quinones
What Would You Do? With John QuinonesWhat Would You Do? With John Quinones
What Would You Do? With John Quinones
 
Politics News and U.S. Elections Coverage
Politics News and U.S. Elections CoveragePolitics News and U.S. Elections Coverage
Politics News and U.S. Elections Coverage
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”
 
U.S. News | National News
U.S. News | National NewsU.S. News | National News
U.S. News | National News
 
Business News, Personal Finance and Money News
Business News, Personal Finance and Money NewsBusiness News, Personal Finance and Money News
Business News, Personal Finance and Money News
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC News
 
Django Class-based views (Slovenian)
Django Class-based views (Slovenian)Django Class-based views (Slovenian)
Django Class-based views (Slovenian)
 

Similar to Tutorial basicapp

Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Mario Jorge Pereira
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_listVlad Kolesnyk
 
Android Testing
Android TestingAndroid Testing
Android TestingEvan Lin
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_listVlad Kolesnyk
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basicsAnton Narusberg
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - AndroidWingston
 
Implementing cast in android
Implementing cast in androidImplementing cast in android
Implementing cast in androidAngelo Rüggeberg
 
Data binding 入門淺談
Data binding 入門淺談Data binding 入門淺談
Data binding 入門淺談awonwon
 
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...Inhacking
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of usOSCON Byrum
 

Similar to Tutorial basicapp (20)

Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
 
Android Testing
Android TestingAndroid Testing
Android Testing
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
 
Mini curso Android
Mini curso AndroidMini curso Android
Mini curso Android
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
Layout
LayoutLayout
Layout
 
YAP / Open Mail Overview
YAP / Open Mail OverviewYAP / Open Mail Overview
YAP / Open Mail Overview
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
Geb qa fest2017
Geb qa fest2017Geb qa fest2017
Geb qa fest2017
 
Implementing cast in android
Implementing cast in androidImplementing cast in android
Implementing cast in android
 
Android 3
Android 3Android 3
Android 3
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
Android app
Android appAndroid app
Android app
 
Android programming basics
Android programming basicsAndroid programming basics
Android programming basics
 
Data binding 入門淺談
Data binding 入門淺談Data binding 入門淺談
Data binding 入門淺談
 
Exercises
ExercisesExercises
Exercises
 
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
 
Action bar
Action barAction bar
Action bar
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 

More from Herry Prasetyo

More from Herry Prasetyo (17)

Luring DI Makasar pelatihan mobile pptx
Luring DI Makasar pelatihan mobile  pptxLuring DI Makasar pelatihan mobile  pptx
Luring DI Makasar pelatihan mobile pptx
 
"Web Development - Inovasi Digital 2024"
"Web Development - Inovasi Digital 2024""Web Development - Inovasi Digital 2024"
"Web Development - Inovasi Digital 2024"
 
Head first laravel
Head first laravelHead first laravel
Head first laravel
 
Modul Laravel
Modul Laravel Modul Laravel
Modul Laravel
 
Modul Ajar Basis Data
Modul Ajar Basis DataModul Ajar Basis Data
Modul Ajar Basis Data
 
WAWASAN KEBANGSAAN DAN NILAI NILAI BELA NEGARA
WAWASAN KEBANGSAAN DAN NILAI NILAI BELA NEGARAWAWASAN KEBANGSAAN DAN NILAI NILAI BELA NEGARA
WAWASAN KEBANGSAAN DAN NILAI NILAI BELA NEGARA
 
MODUL KEDUA.pdf
MODUL KEDUA.pdfMODUL KEDUA.pdf
MODUL KEDUA.pdf
 
Modul Pertama.pdf
Modul Pertama.pdfModul Pertama.pdf
Modul Pertama.pdf
 
CV 2021
CV 2021CV 2021
CV 2021
 
Sertifikat Dicoding
Sertifikat DicodingSertifikat Dicoding
Sertifikat Dicoding
 
Flutter movie apps tutor
Flutter movie apps tutorFlutter movie apps tutor
Flutter movie apps tutor
 
LatihanSederhanaAJA
LatihanSederhanaAJALatihanSederhanaAJA
LatihanSederhanaAJA
 
Laravel[part ii]
Laravel[part ii]Laravel[part ii]
Laravel[part ii]
 
Laravel[part 1]
Laravel[part 1]Laravel[part 1]
Laravel[part 1]
 
Berken
BerkenBerken
Berken
 
Konversi sistem bilangan
Konversi sistem bilanganKonversi sistem bilangan
Konversi sistem bilangan
 
Mengamankan jaringan wifi
Mengamankan jaringan wifiMengamankan jaringan wifi
Mengamankan jaringan wifi
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 

Tutorial basicapp

  • 1. Basic APP Android Java persiapan awal membuat xml : 1. activity_main.xml 2. activity_form.xml 3. activity_spinner.xml 4. activity_listview.xml persiapan membuat java : 1. SpinnerActivity.java 2. FormActivity.java 3. ListviewActivity.java 4. MainActivity.java
  • 2. coding activity_main.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:orientation="vertical" tools:context=".MainActivity"> <Button android:id="@+id/bToast" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button Toast" tools:ignore="MissingConstraints" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/bListView" android:text="Halaman ListView" tools:ignore="MissingConstraints" /> <Button android:id="@+id/bspinner" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Spinner" /> <Button android:id="@+id/bform" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Page Form" /> <Button android:id="@+id/bexit" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Exit" /> </LinearLayout> coding MainActivity.java package com.example.myapplication; import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.app.Activity; import android.content.Intent;
  • 3. import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { Button b1, b2, b3, b4, b5; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button) findViewById(R.id.bToast); b2 =(Button) findViewById(R.id.bListView); b3 = (Button) findViewById(R.id.bspinner); b4 = (Button) findViewById(R.id.bform); b5 = (Button) findViewById(R.id.bexit); b1.setOnClickListener(this); b2.setOnClickListener(this); b3.setOnClickListener(this); b4.setOnClickListener(this); b5.setOnClickListener(this); } @SuppressLint("ResourceType") @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.layout.activity_main, menu); return true; } @Override public void onClick(View v) { switch (v.getId()){ case R.id.bToast: Toast.makeText(this, "This is Notification", Toast.LENGTH_SHORT).show(); break; case R.id.bListView: Intent b = new Intent(MainActivity.this, ListViewActivity.class); startActivity(b); break; case R.id.bform: Intent f = new Intent(MainActivity.this, FormActivity.class); startActivity(f); break; case R.id.bspinner: Intent s = new Intent(MainActivity.this, SpinnerActivity.class); startActivity(s);
  • 4. break; case R.id.bexit: // Toast.makeText(this, "Button Exit", Toast.LENGTH_SHORT).show(); ShowExitDialog(); break; } } private void ShowExitDialog(){ //TODO Auto-generated method stub AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle("Warning"); ad.setMessage("are You sure exit from apps ?"); ad.setPositiveButton("yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { MainActivity.this.finish(); } }); ad.setNegativeButton("no", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { //TODO Auto-generated method stub dialogInterface.dismiss(); } }); ad.show(); } } output :
  • 5. Coding activity_form.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="1">
  • 6. <TableRow android:id="@+id/tableRows" android:layout_height="wrap_content" android:layout_width="wrap_content"> <TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Username" /> <EditText android:id="@+id/inUser" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:hint="username here"> <requestFocus/> </EditText> </TableRow> <TableRow> <TextView android:id="@+id/inpassword" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Password"/> <EditText android:id="@+id/inPass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:hint="password in here"/> </TableRow> </TableLayout> <Button android:id="@+id/bLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="login"/> </LinearLayout> Coding FormActivity.java package com.example.myapplication; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText;
  • 7. import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; public class FormActivity extends Activity { EditText username, pass; Button blogin; String user_name= "user"; String password = "user123"; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_form); username = (EditText) findViewById(R.id.inUser); pass = (EditText) findViewById(R.id.inPass); blogin = (Button) findViewById(R.id.bLogin); blogin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String u = username.getText().toString(); String p = pass.getText().toString(); checkLogin(u, p); } }); } private void checkLogin(String u, String p) { if(p.equals(password) && u.equals(user_name)){ Toast.makeText(this, "Login Success", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(FormActivity.this, MainActivity.class); startActivity(intent); this.finish(); } else{ Toast.makeText(this, "Login Failled", Toast.LENGTH_SHORT).show(); } } }
  • 8. output : Coding activity_spinner.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Spinner android:id="@+id/idSpinner" android:layout_width="match_parent"
  • 9. android:layout_height="wrap_content"/> </LinearLayout> Coding SpinnerActivity.java package com.example.myapplication; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.Toast; import androidx.annotation.Nullable; public class SpinnerActivity extends Activity { Spinner sp; String[] item ={"nasi goreng","mie ayam","nasi uduk","pecel lele","Magelangan","Soto ayam"}; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_spinner); sp = (Spinner)findViewById(R.id.idSpinner); ArrayAdapter<String> array_item = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, item); sp.setAdapter(array_item); sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Toast.makeText(SpinnerActivity.this, "Kamu Memilih" + item[arg2],Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView<?> arg0) { Toast.makeText(SpinnerActivity.this, "Nothing Selected", Toast.LENGTH_SHORT).show(); } }); } }
  • 10. output Coding activity_listview.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  • 11. android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/idListView" android:layout_width="match_parent" android:layout_height="wrap_content"> </ListView> </LinearLayout> Coding ListViewActivity.java package com.example.myapplication; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.Toast; import android.widget.ListView; import androidx.annotation.Nullable; import java.util.List; public class ListViewActivity extends Activity { ListView lv; String[] item = {"Nasi Goreng","Mie Goreng", "Mie Ayam","Magelangan", "Soto Ayam","Sop Ayam","Ayam Goreng"}; @Override protected void onCreate( Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_listview); lv = (ListView) findViewById(R.id.idListView); ArrayAdapter<String> array_item = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, item); lv.setAdapter(array_item); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Toast.makeText(ListViewActivity.this, "Kamu Memilih" + item[arg2], Toast.LENGTH_SHORT).show(); } }); } }