Pada kali ini saya akan share bagaimana membuat Listview Image dengan menggunakan SQLite,,,,
Detail.java (digunakan untuk memanggil databasenya)
Database.java (Untuk isi dari databasenya)
pada values.put("img", R.drawable.note2); taro gambar2 nya di folder drawable yah (kalo belom ada, berarti bikin folder dengan nama 'drawable' (tanpa kutip), di dalam res....
kalo udah, berarti urusan java udah kelar, sekarang pindah ke xml,,,
Buat 3 file xml di layout yaitu : activity_main.xml, detail.xml dan isi_lv.xml...
activity_main.xml
pada android:background="@drawable/search" itu adalah gambar tombol search yg ada di list nantinya,,,,
detail.xml
isi_lv.xml
jangan lupa edit AndroidManifest.xml nya
udah deh,,,, coba run,, dan hasilnya :
jreng2,,,,,,
gampang kan,,,,
kalo udah coba berkali2 tetep error, monggo download source codenya DISINI.....
kalo mau tau pass nya, kirim email ke dimazmarham19@gmail.com,,,
oke....
oke...
oke...
Dimana pada postingan sebelumnya saya telah memposting tentang bagaimana membuat Listview Image dengan Intent class lain,,,,
Untuk class yang sedikit, boleh lah pakai postingan saya yang sebelumnya,,,,
Tapi kalo datanya banyak, wih, harus bikin brp class (java) dan harus di intent satu persatu....
kalo pake SQLite, kita hanya butuh 3 class java + 3 xml aja,,,,,
jadi data2 akan di simpan ke dalam database g usah bikin banyak class,,,,,
gimana cara buatnya???
1. Buat project android baru di eclipse, kali ini saya buat dengan nama DatabaseList (com.dimz.databaselist) dengan contoh aplikasi database hp android..
2. Kita butuh 3 java (MainActivity.java, Detail.java, Database.java)
MainActivity.java (digunakan untuk membuat dan menampilkan listview nya)..
package com.dimz.databaselist;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
protected ListView lv;
protected ListAdapter adapter;
SQLiteDatabase db;
Cursor cursor;
EditText et_db;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = (new Database(this)).getWritableDatabase();
lv = (ListView) findViewById(R.id.lv);
et_db =(EditText) findViewById(R.id.et);
try{
cursor = db.rawQuery("SELECT * FROM sam ORDER BY nama ASC", null);
adapter = new SimpleCursorAdapter(this, R.layout.isi_lv, cursor, new String[] {"nama", "versi", "img"}, new int[] {R.id.tv_nama, R.id.tv_versi, R.id.imV});
lv.setAdapter(adapter);
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View v,
int position, long id) {
detail(position);}
});
}catch(Exception e){
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void search_db(View v){
String edit_db = et_db.getText().toString();
if(!edit_db.equals("")){
try{
cursor = db.rawQuery("SELECT * FROM sam WHERE nama LIKE ?", new String[] {"%" +edit_db+ "%"});
adapter = new SimpleCursorAdapter(this, R.layout.isi_lv, cursor, new String[] {"nama", "versi", "img"}, new int[] {R.id.tv_nama, R.id.tv_versi, R.id.imV});
if(adapter.getCount() == 0){
Toast.makeText(this, "Tidak ditemukan data dengan kata kunci "+edit_db+"", Toast.LENGTH_SHORT).show();
}else{
lv.setAdapter(adapter);
}
}catch(Exception e){
e.printStackTrace();
}
}else{
try{
cursor = db.rawQuery("SELECT * FROM sam ORDER BY nama ASC", null);
adapter = new SimpleCursorAdapter(this, R.layout.isi_lv, cursor, new String[] {"nama", "versi", "img"}, new int[] {R.id.tv_nama, R.id.tv_versi, R.id.imV});
lv.setAdapter(adapter);
lv.setTextFilterEnabled(true);
}catch(Exception e){
e.printStackTrace();
}
}
}
public void detail(int position){
int im = 0;
String _id = "";
String nama = "";
String versi = "";
String layar = "";
String processor = "";
if(cursor.moveToFirst()){
cursor.moveToPosition(position);
im = cursor.getInt(cursor.getColumnIndex("img"));
nama = cursor.getString(cursor.getColumnIndex("nama"));
versi = cursor.getString(cursor.getColumnIndex("versi"));
layar = cursor.getString(cursor.getColumnIndex("layar"));
processor = cursor.getString(cursor.getColumnIndex("processor"));
}
Intent iIntent = new Intent(this, Detail.class);
iIntent.putExtra("dataIM", im);
iIntent.putExtra("dataNama", nama);
iIntent.putExtra("dataVersi", versi);
iIntent.putExtra("dataLayar", layar);
iIntent.putExtra("dataProcessor", processor);
setResult(RESULT_OK, iIntent);
startActivityForResult(iIntent, 99);
}
}
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
protected ListView lv;
protected ListAdapter adapter;
SQLiteDatabase db;
Cursor cursor;
EditText et_db;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = (new Database(this)).getWritableDatabase();
lv = (ListView) findViewById(R.id.lv);
et_db =(EditText) findViewById(R.id.et);
try{
cursor = db.rawQuery("SELECT * FROM sam ORDER BY nama ASC", null);
adapter = new SimpleCursorAdapter(this, R.layout.isi_lv, cursor, new String[] {"nama", "versi", "img"}, new int[] {R.id.tv_nama, R.id.tv_versi, R.id.imV});
lv.setAdapter(adapter);
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View v,
int position, long id) {
detail(position);}
});
}catch(Exception e){
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void search_db(View v){
String edit_db = et_db.getText().toString();
if(!edit_db.equals("")){
try{
cursor = db.rawQuery("SELECT * FROM sam WHERE nama LIKE ?", new String[] {"%" +edit_db+ "%"});
adapter = new SimpleCursorAdapter(this, R.layout.isi_lv, cursor, new String[] {"nama", "versi", "img"}, new int[] {R.id.tv_nama, R.id.tv_versi, R.id.imV});
if(adapter.getCount() == 0){
Toast.makeText(this, "Tidak ditemukan data dengan kata kunci "+edit_db+"", Toast.LENGTH_SHORT).show();
}else{
lv.setAdapter(adapter);
}
}catch(Exception e){
e.printStackTrace();
}
}else{
try{
cursor = db.rawQuery("SELECT * FROM sam ORDER BY nama ASC", null);
adapter = new SimpleCursorAdapter(this, R.layout.isi_lv, cursor, new String[] {"nama", "versi", "img"}, new int[] {R.id.tv_nama, R.id.tv_versi, R.id.imV});
lv.setAdapter(adapter);
lv.setTextFilterEnabled(true);
}catch(Exception e){
e.printStackTrace();
}
}
}
public void detail(int position){
int im = 0;
String _id = "";
String nama = "";
String versi = "";
String layar = "";
String processor = "";
if(cursor.moveToFirst()){
cursor.moveToPosition(position);
im = cursor.getInt(cursor.getColumnIndex("img"));
nama = cursor.getString(cursor.getColumnIndex("nama"));
versi = cursor.getString(cursor.getColumnIndex("versi"));
layar = cursor.getString(cursor.getColumnIndex("layar"));
processor = cursor.getString(cursor.getColumnIndex("processor"));
}
Intent iIntent = new Intent(this, Detail.class);
iIntent.putExtra("dataIM", im);
iIntent.putExtra("dataNama", nama);
iIntent.putExtra("dataVersi", versi);
iIntent.putExtra("dataLayar", layar);
iIntent.putExtra("dataProcessor", processor);
setResult(RESULT_OK, iIntent);
startActivityForResult(iIntent, 99);
}
}
Detail.java (digunakan untuk memanggil databasenya)
package com.dimz.databaselist;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextView;
@SuppressWarnings("deprecation")
public class Detail extends Activity{
ImageView Im;
TextView tv_nama, tv_versi, tv_processor, tv_layar, tv_size, id, namaIm;
Gallery gallery;
ImageSwitcher imageSwitcher;
Integer[] imageIDs = new Integer[3];
int msg_im;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail);
Intent iIdentifikasi = getIntent();
msg_im = iIdentifikasi.getIntExtra("dataIM", 0);
String msg_nama = iIdentifikasi.getStringExtra("dataNama");
String msg_versi = iIdentifikasi.getStringExtra("dataVersi");
String msg_layar = iIdentifikasi.getStringExtra("dataLayar");
String msg_processor = iIdentifikasi.getStringExtra("dataProcessor");
Im = (ImageView) findViewById(R.id.iv_detail);
tv_nama = (TextView) findViewById(R.id.tvNama);
tv_versi = (TextView) findViewById(R.id.tvVersi);
tv_layar = (TextView) findViewById(R.id.tvLayar);
tv_processor = (TextView) findViewById(R.id.tvProcessor);
Im.setImageResource(msg_im);
tv_nama.setText(msg_nama);
tv_versi.setText(msg_versi);
tv_layar.setText(msg_layar);
tv_processor.setText(msg_processor);
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextView;
@SuppressWarnings("deprecation")
public class Detail extends Activity{
ImageView Im;
TextView tv_nama, tv_versi, tv_processor, tv_layar, tv_size, id, namaIm;
Gallery gallery;
ImageSwitcher imageSwitcher;
Integer[] imageIDs = new Integer[3];
int msg_im;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail);
Intent iIdentifikasi = getIntent();
msg_im = iIdentifikasi.getIntExtra("dataIM", 0);
String msg_nama = iIdentifikasi.getStringExtra("dataNama");
String msg_versi = iIdentifikasi.getStringExtra("dataVersi");
String msg_layar = iIdentifikasi.getStringExtra("dataLayar");
String msg_processor = iIdentifikasi.getStringExtra("dataProcessor");
Im = (ImageView) findViewById(R.id.iv_detail);
tv_nama = (TextView) findViewById(R.id.tvNama);
tv_versi = (TextView) findViewById(R.id.tvVersi);
tv_layar = (TextView) findViewById(R.id.tvLayar);
tv_processor = (TextView) findViewById(R.id.tvProcessor);
Im.setImageResource(msg_im);
tv_nama.setText(msg_nama);
tv_versi.setText(msg_versi);
tv_layar.setText(msg_layar);
tv_processor.setText(msg_processor);
}
}
Database.java (Untuk isi dari databasenya)
package com.dimz.databaselist;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Database extends SQLiteOpenHelper{
final static String DB_NAME = "db_samsung";
public Database(Context context) {
super(context, DB_NAME, null, 3);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE IF NOT EXISTS sam(_id INTEGER PRIMARY KEY AUTOINCREMENT, nama TEXT, versi TEXT, layar TEXT, processor TEXT, img BLOB)";
db.execSQL(sql);
ContentValues values = new ContentValues();
values.put("_id", "1");
values.put("nama", "Galaxy Note II");
values.put("versi", "Android 4.1 Jelly Bean");
values.put("layar", "Super AMOLED capacitive touchscreen 16M colors");
values.put("processor", "1.6GHz Quad Core Processor");
values.put("img", R.drawable.note2);
db.insert("sam", "_id", values);
values.put("_id", "2");
values.put("nama", "Galaxy Nexus");
values.put("versi", "Android 4.2.2 Jelly Bean");
values.put("layar", "Super AMOLED capacitive touchscreen 16M colors");
values.put("processor", "1.2Ghz Dual Core Processor");
values.put("img", R.drawable.galnex);//im32 nama file gambar dengan ukuran 80 x 80 pixel yang ada di folder res/drawable pada project
db.insert("sam", "_id", values);
values.put("_id", "3");
values.put("nama", "Galaxy S II");
values.put("versi", "Android 4.1 (Jelly Bean)");
values.put("layar", "Super AMOLED Plus capacitive touchscreen, 16M colors");
values.put("processor", "Dual-core 1.2 GHz Cortex-A9");
values.put("img", R.drawable.galaxys2);
db.insert("sam", "_id", values);
values.put("_id", "4");
values.put("nama", "Galaxy S III");
values.put("versi", "Android 4.2.2 Jelly Bean");
values.put("layar", "Super AMOLED capacitive touchscreen, 16M colors");
values.put("processor", "Quad-core 1.4 GHz Cortex-A9");
values.put("img", R.drawable.galaxys3);
db.insert("sam", "_id", values);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS sam");
onCreate(db);
}
}
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Database extends SQLiteOpenHelper{
final static String DB_NAME = "db_samsung";
public Database(Context context) {
super(context, DB_NAME, null, 3);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE IF NOT EXISTS sam(_id INTEGER PRIMARY KEY AUTOINCREMENT, nama TEXT, versi TEXT, layar TEXT, processor TEXT, img BLOB)";
db.execSQL(sql);
ContentValues values = new ContentValues();
values.put("_id", "1");
values.put("nama", "Galaxy Note II");
values.put("versi", "Android 4.1 Jelly Bean");
values.put("layar", "Super AMOLED capacitive touchscreen 16M colors");
values.put("processor", "1.6GHz Quad Core Processor");
values.put("img", R.drawable.note2);
db.insert("sam", "_id", values);
values.put("_id", "2");
values.put("nama", "Galaxy Nexus");
values.put("versi", "Android 4.2.2 Jelly Bean");
values.put("layar", "Super AMOLED capacitive touchscreen 16M colors");
values.put("processor", "1.2Ghz Dual Core Processor");
values.put("img", R.drawable.galnex);//im32 nama file gambar dengan ukuran 80 x 80 pixel yang ada di folder res/drawable pada project
db.insert("sam", "_id", values);
values.put("_id", "3");
values.put("nama", "Galaxy S II");
values.put("versi", "Android 4.1 (Jelly Bean)");
values.put("layar", "Super AMOLED Plus capacitive touchscreen, 16M colors");
values.put("processor", "Dual-core 1.2 GHz Cortex-A9");
values.put("img", R.drawable.galaxys2);
db.insert("sam", "_id", values);
values.put("_id", "4");
values.put("nama", "Galaxy S III");
values.put("versi", "Android 4.2.2 Jelly Bean");
values.put("layar", "Super AMOLED capacitive touchscreen, 16M colors");
values.put("processor", "Quad-core 1.4 GHz Cortex-A9");
values.put("img", R.drawable.galaxys3);
db.insert("sam", "_id", values);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS sam");
onCreate(db);
}
}
pada values.put("img", R.drawable.note2); taro gambar2 nya di folder drawable yah (kalo belom ada, berarti bikin folder dengan nama 'drawable' (tanpa kutip), di dalam res....
Buat 3 file xml di layout yaitu : activity_main.xml, detail.xml dan isi_lv.xml...
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#FFFFFF" >
<EditText
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/btn" >
<requestFocus />
</EditText>
<Button
android:layout_marginTop="18dp"
android:layout_marginBottom="10dp"
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/search"
android:onClick="search_db"/>
<ListView
android:layout_marginTop="5dp"
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et">
</ListView>
</RelativeLayout>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#FFFFFF" >
<EditText
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/btn" >
<requestFocus />
</EditText>
<Button
android:layout_marginTop="18dp"
android:layout_marginBottom="10dp"
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/search"
android:onClick="search_db"/>
<ListView
android:layout_marginTop="5dp"
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et">
</ListView>
</RelativeLayout>
pada android:background="@drawable/search" itu adalah gambar tombol search yg ada di list nantinya,,,,
detail.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"
android:background="#FFFFFF"
>
<ImageView
android:layout_marginTop="30dp"
android:id="@+id/iv_detail"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:src="@drawable/note2" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" Nama" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" : " />
<TextView
android:id="@+id/tvNama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text="TextView" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" Version" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" : " />
<TextView
android:id="@+id/tvVersi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text="TextView" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" Display" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" : " />
<TextView
android:id="@+id/tvLayar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:maxWidth="15pt"
android:text="TextView" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" CPU" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" : " />
<TextView
android:id="@+id/tvProcessor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text="TextView" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF"
>
<ImageView
android:layout_marginTop="30dp"
android:id="@+id/iv_detail"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:src="@drawable/note2" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" Nama" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" : " />
<TextView
android:id="@+id/tvNama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text="TextView" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" Version" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" : " />
<TextView
android:id="@+id/tvVersi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text="TextView" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" Display" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" : " />
<TextView
android:id="@+id/tvLayar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:maxWidth="15pt"
android:text="TextView" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" CPU" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text=" : " />
<TextView
android:id="@+id/tvProcessor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:text="TextView" />
</TableRow>
</TableLayout>
</LinearLayout>
isi_lv.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="4dp" >
<ImageView
android:id="@+id/imV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv_nama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imV"
android:text="TextView"
android:textSize="10pt"/>
<TextView
android:id="@+id/tv_versi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv_nama"
android:layout_below="@+id/tv_nama"
android:text="TextView" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="4dp" >
<ImageView
android:id="@+id/imV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv_nama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imV"
android:text="TextView"
android:textSize="10pt"/>
<TextView
android:id="@+id/tv_versi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv_nama"
android:layout_below="@+id/tv_nama"
android:text="TextView" />
</RelativeLayout>
jangan lupa edit AndroidManifest.xml nya
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dimz.databaselist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.dimz.databaselist.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="com.dimz.databaselist.Detail" android:label="Detail Smartphone"></activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dimz.databaselist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.dimz.databaselist.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="com.dimz.databaselist.Detail" android:label="Detail Smartphone"></activity>
</application>
</manifest>
udah deh,,,, coba run,, dan hasilnya :
jreng2,,,,,,
gampang kan,,,,
kalo udah coba berkali2 tetep error, monggo download source codenya DISINI.....
kalo mau tau pass nya, kirim email ke dimazmarham19@gmail.com,,,
oke....
oke...
oke...