Assalamuallaikum wr.wb .......
Pada postingan kali ini kita akan belajar bersama mengenal apa itu Listview ,
okee,,,ListView adalah tampilan beberapa item dalam bentuk list yang dapat di scroll secara vertikal. Setiap item akan otomatis dimasukkan kedalam list menggunakan Adapter yang datanya di ambil dari array/database/json/dsb. ListView sering digunakan dalam aplikasi Android, seperti kontak, email, twitter.
Postingan ini saya buat untuk memenuhi salah satu tugas kuliah pada mata pelajaran Mobile Programming .
Disini saya coba membuat contoh Listview dari beberapa bahasa pemrogaraman
langsung saja kita mulai .....
1.Onboarding /splash screen
Java Onboarding
package com.example.yuresa_161021450043;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
public class onboarding extends AppCompatActivity {
private static int SplashDuration = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_onboarding);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
try {
Intent intent = new Intent(getBaseContext(), form_login.class);//StartSlider,MainActivity
startActivity(intent);
finish();
} catch (Exception e){
Log.e("Splash error",e.getMessage());
Intent intent = new Intent(onboarding.this, form_login.class); //MainActivity.class
startActivity(intent);
}
}
}, SplashDuration);
}
}
Xml Onboarding
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".onboarding"
android:background="@drawable/onboarding">
<TextView
android:id="@+id/txt01"
android:layout_width="264dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="132dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="Welcome to Count Me"
android:textColor="@android:color/black"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.408"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/nama"
android:layout_width="165dp"
android:layout_height="76dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="72dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="Yuresa"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.411"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt01" />
<TextView
android:id="@+id/nim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="52dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="161021450043"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.376"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nama" />
</androidx.constraintlayout.widget.ConstraintLayout>
2.Form Login
Java Login
package com.example.yuresa_161021450043;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class form_login extends AppCompatActivity {
EditText id_name,id_password;
Button btnLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form_login);
id_name=findViewById(R.id.id_name);
id_password=findViewById(R.id.id_password);
btnLogin=findViewById(R.id.btnLogin);
id_name.setText("Yuresa@Countme.com");
id_password.setText("123456");
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i=new Intent(form_login.this,calculator.class);
startActivity(i);
}
});
}
}
Xml Login
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".onboarding"
android:background="@drawable/calculator">
<EditText
android:id="@+id/id_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="312dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:textColor="#FF800000"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.421"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/id_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="204dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:textColor="#FF800000"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.421"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnLogin"
android:layout_width="134dp"
android:layout_height="54dp"
android:layout_marginTop="104dp"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.462"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/id_password" />
</androidx.constraintlayout.widget.ConstraintLayout>
3.Listview
package com.example.yuresa_161021450043;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
public ListView listdata ;
// String[] listArray={"ASP","C#","C++","HTML5","Javascript","Java","Objective-C","Perl","PHP","Python","Swift",};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listdata = (ListView)findViewById(R.id.listid);
ArrayList<String> list = new ArrayList<String>();
list.add("ASP");
list.add("Java");
list.add("HTML");
list.add("C++");
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
listdata.setAdapter(arrayAdapter);
listdata.setOnClickListener(new AdapterView.OnItemClickListener()){
public void onItemClick(AdapterView<?> agr0, View arg1, int itemKe,
long arg3){
String itemText=(String) listdata.getItemAtPosition(itemKe);
Tost.makeText(getBaseContext(), "Anda Meng Klik " +itemText, Toast.LENGTH_LONG).show();
if(itemText.equals("ASP")){
Intent I=new Intent(arg0.getContext(),ASP.class);
startActivityForResult(I, 0);
}
}
}
XML Listview
}
}
XML Listview
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity">
<ListView
android:id="@+id/listid"
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
4.Hasil Listview
XML hasil Listview
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
</android.support.constraint.ConstraintLayout>
Semoga bermanfaat bagi kita semuaaa .........
Wassalamuaallaikum wr.wb ......
Yuresa Mutiara Aglis 08.51 New Google SEO Bandung, Indonesia
Assalamuallaikum wr.wb ......
Postingan ini saya buat untuk memenuhi salah satu tugas UTS , pada mata kuliah Mobile Programming .Langsung aja yaaa ...
Lets Check it out
Descripsion :
Apl name : Count Me
Direction : Make your calculate more easy and simple
Design :
1.Onboarding
Berikut source Code nya :
2. Form Login
Berikut Source Code nya :
3.Calculator
Demikian Aplikasi Count Me pada Android , Semoga bermanfaat untuk kita semua .
Thankyou For Watching ....
Assalamuallaikum wr.wb........
Yuresa Mutiara Aglis 07.56 New Google SEO Bandung, Indonesia
Postingan ini saya buat untuk memenuhi salah satu tugas UTS , pada mata kuliah Mobile Programming .Langsung aja yaaa ...
Lets Check it out
Descripsion :
Apl name : Count Me
Direction : Make your calculate more easy and simple
Design :
1.Onboarding
Berikut source Code nya :
package com.example.yuresa_161021450043; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent;import android.os.Bundle;import android.os.Handler;import android.util.Log; public class onboarding extends AppCompatActivity { private static int SplashDuration = 3000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_onboarding); new Handler().postDelayed(new Runnable() { @Override public void run() { try { Intent intent = new Intent(getBaseContext(), form_login.class);//StartSlider,MainActivity startActivity(intent); finish(); } catch (Exception e){ Log.e("Splash error",e.getMessage()); Intent intent = new Intent(onboarding.this, form_login.class); //MainActivity.class startActivity(intent); } } }, SplashDuration); } }
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout 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=".onboarding" android:background="@drawable/onboarding"> <TextView android:id="@+id/txt01" android:layout_width="264dp" android:layout_height="40dp" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="132dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:text="Welcome to Count Me" android:textColor="@android:color/black" android:textSize="24sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.408" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/nama" android:layout_width="165dp" android:layout_height="76dp" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="72dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:text="Yuresa" android:textSize="40sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.411" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/txt01" /> <TextView android:id="@+id/nim" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="52dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:text="161021450043" android:textSize="40sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.376" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/nama" /></androidx.constraintlayout.widget.ConstraintLayout>
2. Form Login
Berikut Source Code nya :
package com.example.yuresa_161021450043; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText; public class form_login extends AppCompatActivity { EditText id_name,id_password; Button btnLogin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_form_login); id_name=findViewById(R.id.id_name); id_password=findViewById(R.id.id_password); btnLogin=findViewById(R.id.btnLogin); id_name.setText("Yuresa@Countme.com"); id_password.setText("123456"); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i=new Intent(form_login.this,calculator.class); startActivity(i); } }); } }
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout 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=".onboarding" android:background="@drawable/calculator"> <EditText android:id="@+id/id_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="312dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:ems="10" android:textColor="#FF800000" android:inputType="textPersonName" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.421" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <EditText android:id="@+id/id_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="204dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:ems="10" android:textColor="#FF800000" android:inputType="textPersonName" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.421" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/btnLogin" android:layout_width="134dp" android:layout_height="54dp" android:layout_marginTop="104dp" android:text="Login" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.462" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/id_password" /></androidx.constraintlayout.widget.ConstraintLayout>
3.Calculator
package com.example.yuresa_161021450043; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView; public class calculator extends AppCompatActivity { EditText Input1,Input2; Button Bagi,Kali,Tambah,Kurang; TextView hasil; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calculator); Input1=findViewById(R.id.input1); Input2=findViewById(R.id.input2); hasil=findViewById(R.id.hasil); Bagi=findViewById(R.id.Bagi); Kali=findViewById(R.id.Kali); Tambah=findViewById(R.id.Tambah); Kurang=findViewById(R.id.Kurang); Bagi.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String a1 = Input1.getText().toString(); Integer aVal = Integer.parseInt(a1); String a2 = Input2.getText().toString(); Integer bVal = Integer.parseInt(a2); int total ; total = aVal / bVal ; hasil.setText(String.valueOf(total)); } }); Kali.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String a1 = Input1.getText().toString(); Integer aVal = Integer.parseInt(a1); String a2 = Input2.getText().toString(); Integer bVal = Integer.parseInt(a2); int total ; total = aVal * bVal ; hasil.setText(String.valueOf(total)); } }); Tambah.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String a1 = Input1.getText().toString(); Integer aVal = Integer.parseInt(a1); String a2 = Input2.getText().toString(); Integer bVal = Integer.parseInt(a2); int total ; total = aVal + bVal ; hasil.setText(String.valueOf(total)); } }); Kurang.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String a1 = Input1.getText().toString(); Integer aVal = Integer.parseInt(a1); String a2 = Input2.getText().toString(); Integer bVal = Integer.parseInt(a2); int total ; total = aVal - bVal ; hasil.setText(String.valueOf(total)); } }); } }
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout 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=".onboarding"> <Button android:id="@+id/Bagi" android:layout_width="69dp" android:layout_height="64dp" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="248dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:text=":" app:layout_constraintEnd_toStartOf="@+id/Kali" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/input2" /> <Button android:id="@+id/Kurang" android:layout_width="72dp" android:layout_height="66dp" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="194dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:text="-" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/Tambah" app:layout_constraintTop_toBottomOf="@+id/hasil" /> <Button android:id="@+id/Kali" android:layout_width="67dp" android:layout_height="66dp" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="192dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:text="X" app:layout_constraintEnd_toStartOf="@+id/Tambah" app:layout_constraintStart_toEndOf="@+id/Bagi" app:layout_constraintTop_toBottomOf="@+id/hasil" /> <Button android:id="@+id/Tambah" android:layout_width="72dp" android:layout_height="66dp" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="192dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:text="+" app:layout_constraintEnd_toStartOf="@+id/Kurang" app:layout_constraintStart_toEndOf="@+id/Kali" app:layout_constraintTop_toBottomOf="@+id/hasil" /> <EditText android:id="@+id/input1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="124dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:ems="10" android:inputType="textPersonName" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <EditText android:id="@+id/input2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="28dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:ems="10" android:inputType="textPersonName" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/input1" /> <TextView android:id="@+id/countme" android:layout_width="74dp" android:layout_height="40dp" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="48dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:text="CountMe" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.498" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/hasil" android:layout_width="383dp" android:layout_height="38dp" android:layout_marginStart="16dp" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/input2" />
Demikian Aplikasi Count Me pada Android , Semoga bermanfaat untuk kita semua .
Thankyou For Watching ....
Assalamuallaikum wr.wb........
Yuresa Mutiara Aglis 07.56 New Google SEO Bandung, Indonesia