I making project that user can scanning a barcode. My problem is, if the scanning results are the same as the kode_obat column, then the nama_obat, and harga_jual columns will be displayed or setText to Textview.
Please help me, How should I code ?
Here my Code :
MyDatabaseHelper.class
private Context context;
private static final String DATABASE_NAME = "Apotek.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "obat";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_KODEOBAT = "kode_obat";
private static final String COLUMN_NAMAOBAT = "nama_obat";
//private static final String COLUMN_NOBATCH = "no_batch";
private static final String COLUMN_DISTRIBUTOR = "distributor";
private static final String COLUMN_EXPIRED = "expired_obat";
private static final String COLUMN_SATUAN = "satuan";
private static final String COLUMN_HARGASATUAN = "harga_satuan";
private static final String COLUMN_HARGAJUAL = "harga_jual";
private static final String COLUMN_PRODUSEN = "produsen";
//private static final String COLUMN_STOK = "stok_obat";
//private static final String COLUMN_HARGAOBAT = "harga_obat";
MyDatabaseHelper(@Nullable Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " TABLE_NAME
" (" COLUMN_ID " INTEGER PRIMARY KEY AUTOINCREMENT, "
COLUMN_KODEOBAT " TEXT, "
COLUMN_NAMAOBAT " TEXT, "
COLUMN_DISTRIBUTOR " TEXT, "
COLUMN_EXPIRED " TEXT, "
COLUMN_SATUAN " TEXT, "
COLUMN_HARGASATUAN " INTEGER, "
COLUMN_HARGAJUAL " INTEGER, "
COLUMN_PRODUSEN " TEXT);";
db.execSQL(query);
String query1 = "CREATE TABLE " TABLE_NAME1
" (" COLUMN_ID " INTEGER PRIMARY KEY AUTOINCREMENT, "
COLUMN_DATE " TEXT, "
COLUMN_BAYAR " INTEGER);";
db.execSQL(query1);
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXISTS " TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " TABLE_NAME1);
onCreate(db);
}
void addObat(String kodeobat, String namaobat, String distributor, String expired, String satuan, int hargasatuan, int hargajual, String produsen){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COLUMN_KODEOBAT, kodeobat);
cv.put(COLUMN_NAMAOBAT, namaobat);
cv.put(COLUMN_DISTRIBUTOR, distributor);
cv.put(COLUMN_EXPIRED, expired);
cv.put(COLUMN_SATUAN, satuan);
cv.put(COLUMN_HARGASATUAN, hargasatuan);
cv.put(COLUMN_HARGAJUAL, hargajual);
cv.put(COLUMN_PRODUSEN, produsen);
long result = db.insert(TABLE_NAME,null, cv);
if(result == -1){
Toast.makeText(context, "Failed", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "Added Successfully!", Toast.LENGTH_SHORT).show();
}
}
void addLaporan(String date, String bayar){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COLUMN_DATE, date);
cv.put(COLUMN_BAYAR, bayar);
long result = db.insert(TABLE_NAME1,null, cv);
if(result == -1){
Toast.makeText(context, "Failed", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "Added Successfully!", Toast.LENGTH_SHORT).show();
}
}
Cursor readAllData(){
String query = "SELECT * FROM " TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = null;
if(db != null){
cursor = db.rawQuery(query, null);
}
return cursor;
}
Cursor readAllDataLaporan(){
String query = "SELECT * FROM " TABLE_NAME1;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = null;
if(db != null){
cursor = db.rawQuery(query, null);
}
return cursor;
}
void updateObat(String row_id, String kodeobat, String namaobat, String distributor, String expired, String satuan, String hargasatuan, String hargajual, String produsen){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COLUMN_KODEOBAT, kodeobat);
cv.put(COLUMN_NAMAOBAT, namaobat);
cv.put(COLUMN_DISTRIBUTOR, distributor);
cv.put(COLUMN_EXPIRED, expired);
cv.put(COLUMN_SATUAN, satuan);
cv.put(COLUMN_HARGASATUAN, hargasatuan);
cv.put(COLUMN_HARGAJUAL, hargajual);
cv.put(COLUMN_PRODUSEN, produsen);
long result = db.update(TABLE_NAME, cv, "_id=?", new String[]{row_id});
if(result == -1){
Toast.makeText(context, "Failed", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "Updated Successfully!", Toast.LENGTH_SHORT).show();
}
}
void updateData(String row_id, String date, String bayar){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COLUMN_DATE, date);
cv.put(COLUMN_BAYAR, bayar);
long result = db.update(TABLE_NAME1, cv, "_id=?", new String[]{row_id});
if(result == -1){
Toast.makeText(context, "Failed", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "Updated Successfully!", Toast.LENGTH_SHORT).show();
}
}
void deleteOneRow(String row_id){
SQLiteDatabase db = this.getWritableDatabase();
long result = db.delete(TABLE_NAME, "_id=?", new String[]{row_id});
if(result == -1){
Toast.makeText(context, "Failed to Delete.", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "Successfully Deleted.", Toast.LENGTH_SHORT).show();
}
}
void deleteData(String row_id){
SQLiteDatabase db = this.getWritableDatabase();
long result = db.delete(TABLE_NAME1, "_id=?", new String[]{row_id});
if(result == -1){
Toast.makeText(context, "Failed to Delete.", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "Successfully Deleted.", Toast.LENGTH_SHORT).show();
}
}
void deleteAllData(){
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM " TABLE_NAME);
}
TransaksiActivity.class
EditText ETnamaobattransaksi1, ETnamaobattransaksi2,ETnamaobattransaksi3, ETnamaobattransaksi4, ETnamaobattransaksi5, ETnamaobattransaksi6, ETnamaobattransaksi7,ETnamaobattransaksi8,ETnamaobattransaksi9,ETnamaobattransaksi10,
EThargaobattransaksi1, EThargaobattransaksi2, EThargaobattransaksi3, EThargaobattransaksi4, EThargaobattransaksi5, EThargaobattransaksi6, EThargaobattransaksi7, EThargaobattransaksi8, EThargaobattransaksi9, EThargaobattransaksi10,
ETjumlahobattransaksi1, ETjumlahobattransaksi2, ETjumlahobattransaksi3, ETjumlahobattransaksi4, ETjumlahobattransaksi5 , ETjumlahobattransaksi6, ETjumlahobattransaksi7, ETjumlahobattransaksi8, ETjumlahobattransaksi9 ,ETjumlahobattransaksi10, ETcash;
Button BTNScan, BTNcetak, BTNtotal, BTNkembalian;
TextView TVtotalobat1, TVtotalobat2, TVtotalobat3, TVtotalobat4, TVtotalobat5,TVtotalobat6, TVtotalobat7, TVtotalobat8, TVtotalobat9, TVtotalobat10, TVdate, TVTotalhitungtransaksi, TVTotalhitungtransaksiclick, TVkembalian;
int total1,total2=0,total3=0,total4=0,total5=0,total6=0,total7=0,total8=0,total9=0, total10=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transaksi);
Calendar calendar = Calendar.getInstance();
String currentDate = DateFormat.getDateInstance(DateFormat.FULL).format(calendar.getTime());
TVdate = findViewById(R.id.TVdate);
TVdate.setText(currentDate);
ETnamaobattransaksi1 = findViewById(R.id.ETnamaobattransaksi1);
ETnamaobattransaksi2 = findViewById(R.id.ETnamaobattransaksi2);
ETnamaobattransaksi3 = findViewById(R.id.ETnamaobattransaksi3);
ETnamaobattransaksi4 = findViewById(R.id.ETnamaobattransaksi4);
ETnamaobattransaksi5 = findViewById(R.id.ETnamaobattransaksi5);
ETnamaobattransaksi6 = findViewById(R.id.ETnamaobattransaksi6);
ETnamaobattransaksi7 = findViewById(R.id.ETnamaobattransaksi7);
ETnamaobattransaksi8 = findViewById(R.id.ETnamaobattransaksi8);
ETnamaobattransaksi9 = findViewById(R.id.ETnamaobattransaksi9);
ETnamaobattransaksi10 = findViewById(R.id.ETnamaobattransaksi10);
EThargaobattransaksi1 = findViewById(R.id.EThargaobattransaksi1);
EThargaobattransaksi2 = findViewById(R.id.EThargaobattransaksi2);
EThargaobattransaksi3 = findViewById(R.id.EThargaobattransaksi3);
EThargaobattransaksi4 = findViewById(R.id.EThargaobattransaksi4);
EThargaobattransaksi5 = findViewById(R.id.EThargaobattransaksi5);
EThargaobattransaksi6 = findViewById(R.id.EThargaobattransaksi6);
EThargaobattransaksi7 = findViewById(R.id.EThargaobattransaksi7);
EThargaobattransaksi8 = findViewById(R.id.EThargaobattransaksi8);
EThargaobattransaksi9 = findViewById(R.id.EThargaobattransaksi9);
EThargaobattransaksi10 = findViewById(R.id.EThargaobattransaksi10);
ETjumlahobattransaksi1 = findViewById(R.id.ETjumlahobattransaksi1);
ETjumlahobattransaksi2 = findViewById(R.id.ETjumlahobattransaksi2);
ETjumlahobattransaksi3 = findViewById(R.id.ETjumlahobattransaksi3);
ETjumlahobattransaksi4 = findViewById(R.id.ETjumlahobattransaksi4);
ETjumlahobattransaksi5 = findViewById(R.id.ETjumlahobattransaksi5);
ETjumlahobattransaksi6 = findViewById(R.id.ETjumlahobattransaksi6);
ETjumlahobattransaksi7 = findViewById(R.id.ETjumlahobattransaksi7);
ETjumlahobattransaksi8 = findViewById(R.id.ETjumlahobattransaksi8);
ETjumlahobattransaksi9 = findViewById(R.id.ETjumlahobattransaksi9);
ETjumlahobattransaksi10 = findViewById(R.id.ETjumlahobattransaksi10);
TVtotalobat1 = findViewById(R.id.ETtotalobat1);
TVtotalobat2 = findViewById(R.id.ETtotalobat2);
TVtotalobat3 = findViewById(R.id.ETtotalobat3);
TVtotalobat4 = findViewById(R.id.ETtotalobat4);
TVtotalobat5 = findViewById(R.id.ETtotalobat5);
TVtotalobat6 = findViewById(R.id.ETtotalobat6);
TVtotalobat7 = findViewById(R.id.ETtotalobat7);
TVtotalobat8 = findViewById(R.id.ETtotalobat8);
TVtotalobat9 = findViewById(R.id.ETtotalobat9);
TVtotalobat10 = findViewById(R.id.ETtotalobat10);
BTNtotal = findViewById(R.id.BTNtotal);
TVTotalhitungtransaksi = findViewById(R.id.TVTotalhitungtransaksi);
BTNkembalian = findViewById(R.id.BTNkembalian);
TVkembalian = findViewById(R.id.TVkembalian);
ETcash = findViewById(R.id.ETcash);
BTNcetak = findViewById(R.id.BTNcetak);
BTNcetak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MyDatabaseHelper myDB = new MyDatabaseHelper(TransaksiActivity.this);
myDB.addLaporan(currentDate.toString().trim(),
TVTotalhitungtransaksi.getText().toString().trim());
}
});
BTNScan = findViewById(R.id.BTNscan);
BTNScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scanCode();
}
});
BTNtotal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String harga1 = EThargaobattransaksi1.getText().toString();
String jumlah1 = ETjumlahobattransaksi1.getText().toString();
String harga2 = EThargaobattransaksi2.getText().toString();
String jumlah2 = ETjumlahobattransaksi2.getText().toString();
String harga3 = EThargaobattransaksi3.getText().toString();
String jumlah3 = ETjumlahobattransaksi3.getText().toString();
String harga4 = EThargaobattransaksi4.getText().toString();
String jumlah4 = ETjumlahobattransaksi4.getText().toString();
String harga5 = EThargaobattransaksi5.getText().toString();
String jumlah5 = ETjumlahobattransaksi5.getText().toString();
String harga6 = EThargaobattransaksi6.getText().toString();
String jumlah6 = ETjumlahobattransaksi6.getText().toString();
String harga7 = EThargaobattransaksi7.getText().toString();
String jumlah7 = ETjumlahobattransaksi7.getText().toString();
String harga8 = EThargaobattransaksi8.getText().toString();
String jumlah8 = ETjumlahobattransaksi8.getText().toString();
String harga9 = EThargaobattransaksi9.getText().toString();
String jumlah9 = ETjumlahobattransaksi9.getText().toString();
String harga10 = EThargaobattransaksi10.getText().toString();
String jumlah10 = ETjumlahobattransaksi10.getText().toString();
if(harga1.equals("")&&jumlah1.equals(""))
{
int harga1int = 0;
int jumlah1int = 0;
total1 = (harga1int*jumlah1int);
}
else
{
int harga1int = Integer.parseInt(harga1);
int jumlah1int = Integer.parseInt(jumlah1);
total1 = (harga1int*jumlah1int);
}
if(harga2.equals("")&&jumlah2.equals(""))
{
int harga2int = 0;
int jumlah2int = 0;
total2 = (harga2int*jumlah2int);
}
else
{
int harga2int = Integer.parseInt(harga2);
int jumlah2int = Integer.parseInt(jumlah2);
total2 = (Integer.parseInt(harga2)*Integer.parseInt(jumlah2));
}
if(harga3.equals("")&&jumlah3.equals(""))
{
int harga3int = 0;
int jumlah3int = 0;
total3 = (harga3int*jumlah3int);
}
else
{
int harga3int = Integer.parseInt(harga3);
int jumlah3int = Integer.parseInt(jumlah3);
total3 = (Integer.parseInt(harga3)*Integer.parseInt(jumlah3));
}
if(harga4.equals("")&&jumlah4.equals(""))
{
int harga4int = 0;
int jumlah4int = 0;
total4 = (harga4int*jumlah4int);
}
else
{
int harga4int = Integer.parseInt(harga4);
int jumlah4int = Integer.parseInt(jumlah4);
total4 = (Integer.parseInt(harga4)*Integer.parseInt(jumlah4));
}
if(harga5.equals("")&&jumlah5.equals(""))
{
int harga5int = 0;
int jumlah5int = 0;
total5 = (harga5int*jumlah5int);
}
else
{
int harga5int = Integer.parseInt(harga5);
int jumlah5int = Integer.parseInt(jumlah5);
total5 = (Integer.parseInt(harga5)*Integer.parseInt(jumlah5));
}
if(harga6.equals("")&&jumlah6.equals(""))
{
int harga6int = 0;
int jumlah6int = 0;
total6 = (harga6int*jumlah6int);
}
else
{
int harga6int = Integer.parseInt(harga6);
int jumlah6int = Integer.parseInt(jumlah6);
total6 = (Integer.parseInt(harga6)*Integer.parseInt(jumlah6));
}
if(harga7.equals("")&&jumlah7.equals(""))
{
int harga7int = 0;
int jumlah7int = 0;
total7 = (harga7int*jumlah7int);
}
else
{
int harga7int = Integer.parseInt(harga7);
int jumlah7int = Integer.parseInt(jumlah7);
total7 = (Integer.parseInt(harga7)*Integer.parseInt(jumlah7));
}
if(harga8.equals("")&&jumlah8.equals(""))
{
int harga8int = 0;
int jumlah8int = 0;
total8 = (harga8int*jumlah8int);
}
else
{
int harga8int = Integer.parseInt(harga8);
int jumlah8int = Integer.parseInt(jumlah8);
total8 = (Integer.parseInt(harga8)*Integer.parseInt(jumlah8));
}
if(harga9.equals("")&&jumlah9.equals(""))
{
int harga9int = 0;
int jumlah9int = 0;
total9 = (harga9int*jumlah9int);
}
else
{
int harga9int = Integer.parseInt(harga9);
int jumlah9int = Integer.parseInt(jumlah9);
total9 = (Integer.parseInt(harga9)*Integer.parseInt(jumlah9));
}
if(harga10.equals("")&&jumlah10.equals(""))
{
int harga10int = 0;
int jumlah10int = 0;
total10 = (harga10int*jumlah10int);
}
else
{
int harga10int = Integer.parseInt(harga10);
int jumlah10int = Integer.parseInt(jumlah10);
total10 = (Integer.parseInt(harga10)*Integer.parseInt(jumlah10));
}
int totalbayar = (total1 total2 total3 total4 total5 total6 total7 total8 total9 total10);
//int totalbayar = (total1);
TVtotalobat1.setText("Rp." String.valueOf(total1));
TVtotalobat2.setText("Rp." String.valueOf(total2));
TVtotalobat3.setText("Rp." String.valueOf(total3));
TVtotalobat4.setText("Rp." String.valueOf(total4));
TVtotalobat5.setText("Rp." String.valueOf(total5));
TVtotalobat6.setText("Rp." String.valueOf(total6));
TVtotalobat7.setText("Rp." String.valueOf(total7));
TVtotalobat8.setText("Rp." String.valueOf(total8));
TVtotalobat9.setText("Rp." String.valueOf(total9));
TVtotalobat10.setText("Rp." String.valueOf(total10));
//String texttotalbayar = String.valueOf(totalbayar);
TVTotalhitungtransaksi.setText("Rp." String.valueOf(totalbayar));
BTNkembalian.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String bayar = ETcash.getText().toString();
int bayarint = Integer.parseInt(bayar);
int kembalian = bayarint - totalbayar;
TVkembalian.setText(String.valueOf("Rp." kembalian));
}
});
private void scanCode()
{
ScanOptions options = new ScanOptions();
options.setPrompt("Volume to flash on");
options.setBeepEnabled(true);
options.setOrientationLocked(true);
options.setCaptureActivity(CaptureAct.class);
barLauncher.launch(options);
}
ActivityResultLauncher<ScanOptions> barLauncher = registerForActivityResult(new ScanContract(), result ->
{
if(result.getContents() !=null)
{
String namaobattransaksi1 = ETnamaobattransaksi1.getText().toString();
String namaobattransaksi2 = ETnamaobattransaksi2.getText().toString();
String namaobattransaksi3 = ETnamaobattransaksi3.getText().toString();
String namaobattransaksi4 = ETnamaobattransaksi4.getText().toString();
String namaobattransaksi5 = ETnamaobattransaksi5.getText().toString();
String namaobattransaksi6 = ETnamaobattransaksi6.getText().toString();
String namaobattransaksi7 = ETnamaobattransaksi7.getText().toString();
String namaobattransaksi8 = ETnamaobattransaksi8.getText().toString();
String namaobattransaksi9 = ETnamaobattransaksi9.getText().toString();
String namaobattransaksi10 = ETnamaobattransaksi10.getText().toString();
for(int f = 1; f<10; f ){
}
AlertDialog.Builder builder = new AlertDialog.Builder(TransaksiActivity.this);
//ETnamaobat.setText(result.getContents());
if(namaobattransaksi1.equals(""))
{
ETnamaobattransaksi1.setText(result.getContents());
}
else if (namaobattransaksi2.equals(""))
{
ETnamaobattransaksi2.setText(result.getContents());
}
else if (namaobattransaksi3.equals(""))
{
ETnamaobattransaksi3.setText(result.getContents());
}
else if (namaobattransaksi4.equals(""))
{
ETnamaobattransaksi4.setText(result.getContents());
}
else if (namaobattransaksi5.equals(""))
{
ETnamaobattransaksi5.setText(result.getContents());
}
else if (namaobattransaksi6.equals(""))
{
ETnamaobattransaksi6.setText(result.getContents());
}
else if (namaobattransaksi7.equals(""))
{
ETnamaobattransaksi7.setText(result.getContents());
}
else if (namaobattransaksi8.equals(""))
{
ETnamaobattransaksi8.setText(result.getContents());
}
else if (namaobattransaksi9.equals(""))
{
ETnamaobattransaksi9.setText(result.getContents());
}
else{
ETnamaobattransaksi10.setText(result.getContents());
}
builder.setTitle("Result");
builder.setMessage(result.getContents());
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
}).show();
}
result.getContents().equals(null);
});
activity_transaksi.xml
<ScrollView 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"
android:padding="10dp"
android:id="@ id/utama"
android:stretchColumns="1,2,3"
android:layout_margin="10dp"
android:divider="?android:attr/dividerHorizontal"
tools:context=".TransaksiActivity"
android:showDividers="middle">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:id="@ id/TVdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:textSize="18dp"
android:textAlignment="center"
android:layout_span="4"
android:textStyle="bold"
android:layout_margin="20dp"
android:layout_column="1"/>
</TableRow>
<TableRow>
<EditText
android:id="@ id/ETnamaobattransaksi1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nama Obat"
android:textSize="15dp"
android:textStyle="bold"
android:textAlignment="center"
android:layout_column="1"/>
<EditText
android:id="@ id/ETjumlahobattransaksi1"
android:layout_width="27dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:hint="Jumlah"
android:inputType="number"
android:textAlignment="center"
android:textSize="15dp"
android:textStyle="bold" />
<EditText
android:id="@ id/EThargaobattransaksi1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Harga Obat"
android:textSize="15dp"
android:inputType="number"
android:textStyle="bold"
android:textAlignment="center"
android:layout_column="1"/>
<TextView
android:id="@ id/ETtotalobat1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Total Obat"
android:textSize="15dp"
android:inputType="number"
android:textStyle="bold"
android:textColor="@color/black"
android:textAlignment="center"
android:layout_column="1"/>
</TableRow>
<TableRow>
<TableRow>
<!--<TextView
android:id="@ id/TVTotalhitungtransaksiclick"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="Total : Rp."
android:gravity="right"
android:textSize="15sp"
android:textStyle="bold"
android:layout_marginRight="30dp"
android:paddingTop="15dp"
android:textColor="@color/black"
android:layout_column="1"
android:layout_span="3"
/>-->
<Button
android:id="@ id/BTNtotal"
android:layout_width="85sp"
android:layout_height="40sp"
android:backgroundTint="#5a8f7b"
android:text="total"
android:textColor="@color/white"
android:layout_column="1"
android:layout_span="3"
android:layout_gravity="right"
android:textSize="10sp" />
<TextView
android:id="@ id/TVTotalhitungtransaksi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="4"
android:hint="Total"
android:layout_gravity="center"
android:textAlignment="center"
android:textColor="@color/black"
android:textColorHint="#A2B5BB"
android:textSize="15sp"
android:textStyle="bold" />
<!--<View
android:id="@ id/line1"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_weight="1"
android:background="#00FFFFFF"
android:padding="2dip" />-->
</TableRow>
<TableRow>
<Button
android:id="@ id/BTNscan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="scan"
android:textSize="24dp"
android:layout_span="4"
android:layout_column="1"/>
</TableRow>
</TableLayout>
</ScrollView>
CodePudding user response:
to do the search in the database thing you will need to add this code.
SQLiteDatabase database = new MyDatabaseHelper(context).getReadableDatabase();
@SuppressLint("Recycle") Cursor cursor = database.rawQuery("SELECT "
MyDatabaseHelper.COLUMN_NAMAOBAT " , " MyDatabaseHelper.COLUMN_HARGAJUAL " FROM " MyDatabaseHelper.TABLE_NAME " WHERE " MyDatabaseHelper.COLUMN_KODEOBAT " = '" YOUR_TEXT_HERE "'", null);
if(cursor.getCount()>0){
cursor.moveToFirst();
YOUR_TEXTVIEW1.setText(cursor.getString(0));
YOUR_TEXTVIEW2.setText(cursor.getString(1));
}
else{
DO_YOUR_CODE_HERE
}
I hope this will help.
And you didn't have to post all of the code just a small sample, Actually, in your case, you don't have to post any of this.