public class MainActivity extends AppCompatActivity {
private EditText etDescription, etAmount;
private RadioGroup rgTransactionType;
private Button btnSave;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etDescription = findViewById(R.id.etDescription);
etAmount = findViewById(R.id.etAmount);
rgTransactionType = findViewById(R.id.rgTransactionType);
btnSave = findViewById(R.id.btnSave);
btnSave.setOnClickListener(v -> saveTransaction());
}
private void saveTransaction() {
String description = etDescription.getText().toString();
double amount = Double.parseDouble(etAmount.getText().toString());
int selectedId = rgTransactionType.getCheckedRadioButtonId();
if (selectedId == R.id.rbIncome) {
// Simpan sebagai pendapatan
} else if (selectedId == R.id.rbExpense) {
// Simpan sebagai pengeluaran
}
// Simpan data ke database atau shared preferences
Toast.makeText(this, "Transaksi disimpan", Toast.LENGTH_SHORT).show();
}
}public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "pembukuan.db";
private static final int DATABASE_VERSION = 1;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE transactions (id INTEGER PRIMARY KEY AUTOINCREMENT, description TEXT, amount REAL, type TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS transactions");
onCreate(db);
}
}