package com.example.contohentridatabase;
//Author : midasoft.blogspot.com
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class CreateData extends Activity implements OnClickListener{
//inisilisasi elemen-elemen pada layout
private Button buttonSubmit;
private EditText edNama;
private EditText edMerk;
private EditText edHarga;
//inisialisasi kontroller/Data Source
private DBDataSourceMob dataSource;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_create);
buttonSubmit = (Button) findViewById(R.id.buttom_submit);
buttonSubmit.setOnClickListener(this);
edNama = (EditText) findViewById(R.id.nama_barang);
edHarga = (EditText) findViewById(R.id.harga_barang);
edMerk = (EditText) findViewById(R.id.merk_barang);
// instanstiasi kelas DBDataSource
dataSource = new DBDataSourceMob(this);
//membuat sambungan gres ke database
dataSource.open();
}
//Ketika Tombol Submit diklik
@Override
public void onClick(View v) {
// Inisialisasi data barang
String nama = null;
String brand = null;
String harga = null;
@SuppressWarnings("unused")
//inisialisasi barang gres
Barang barang = null;
if(edNama.getText()!=null && edMerk.getText()!=null && edHarga.getText()!=null)
{
/* kalau field nama, merk, dan harga dihentikan dikosongkan
* maka masukkan ke dalam data barang*/
nama = edNama.getText().toString();
brand = edMerk.getText().toString();
harga = edHarga.getText().toString();
}
switch(v.getId())
{
case R.id.buttom_submit:
// insert data barang baru
barang = dataSource.createBarang(nama, merk, harga);
//konfirmasi
Toast.makeText(this, "Data Tersimpan\n" +
"nama" + barang.getNama_barang() +
"merk" + barang.getMerk_barang() +
"harga" + barang.getHarga_barang(), Toast.LENGTH_LONG).show();
break;
}
}
}
0 Response to "Source Code Entridata.Java Ke Database Sqlite Pada Aplikasi Android"