Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package id.dismut.bmi;
- import android.app.ActionBar;
- import android.app.Activity;
- import android.app.Dialog;
- import android.content.Intent;
- import android.database.Cursor;
- import android.database.SQLException;
- import android.database.sqlite.SQLiteDatabase;
- import android.graphics.Color;
- import android.graphics.drawable.ColorDrawable;
- import android.os.Bundle;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.Window;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- public class Pengaturan extends Activity {
- Button btnNama,btnUsername,btnPassword,btnData,btnOk,btnCancel;
- EditText txtNama;
- String nama;
- protected Cursor cursor;
- DataHelper dbHelper;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_pengaturan);
- ActionBar actionBar = getActionBar();
- actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0091ea")));
- getActionBar().setDisplayHomeAsUpEnabled(true);
- dbHelper = new DataHelper(this);
- final SQLiteDatabase db = dbHelper.getReadableDatabase();
- btnNama = (Button) findViewById(R.id.btnNama);
- btnUsername = (Button) findViewById(R.id.btnUsername);
- btnPassword = (Button) findViewById(R.id.btnPassword);
- btnData = (Button) findViewById(R.id.btnData);
- btnNama.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final Dialog dialog = new Dialog(Pengaturan.this);
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- dialog.setContentView(R.layout.dialog_nama);
- txtNama = (EditText) dialog.findViewById(R.id.txtNama);
- btnOk = (Button) dialog.findViewById(R.id.button2);
- btnCancel = (Button) dialog.findViewById(R.id.button1);
- nama = txtNama.getText().toString();
- btnOk.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- String sql = "UPDATE user SET nama = '"+nama+"' WHERE username = (SELECT username FROM session)";
- try {
- db.execSQL(sql);
- Toast.makeText(getBaseContext(), "Berhasil mengubah "+nama+" ll", Toast.LENGTH_SHORT).show();
- dialog.dismiss();
- }
- catch (SQLException e) {
- Toast.makeText(getBaseContext(), "Gagal mengubah", Toast.LENGTH_SHORT).show();
- }
- }
- });
- dialog.show();
- }
- });
- btnUsername.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final Dialog dialog = new Dialog(Pengaturan.this);
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- dialog.setContentView(R.layout.dialog_username);
- EditText txtUsername = (EditText) dialog.findViewById(R.id.txtUsername);
- Button btnOk = (Button) dialog.findViewById(R.id.button2);
- Button btnCancel = (Button) dialog.findViewById(R.id.button1);
- dialog.show();
- }
- });
- btnPassword.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final Dialog dialog = new Dialog(Pengaturan.this);
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- dialog.setContentView(R.layout.dialog_password);
- EditText txtPasswordLama = (EditText) dialog.findViewById(R.id.txtUsername);
- EditText txtPasswordBaru = (EditText) dialog.findViewById(R.id.txtPasswordBaru);
- EditText txtPasswordBaruUlang = (EditText) dialog.findViewById(R.id.txtPasswordBaru);
- Button btnOk = (Button) dialog.findViewById(R.id.button2);
- Button btnCancel = (Button) dialog.findViewById(R.id.button1);
- dialog.show();
- }
- });
- btnData.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final Dialog dialog = new Dialog(Pengaturan.this);
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
- dialog.setContentView(R.layout.dialog_confirm);
- TextView judul = (TextView) dialog.findViewById(R.id.txtJudul);
- TextView isi = (TextView) dialog.findViewById(R.id.txtIsi);
- Button btnOk = (Button) dialog.findViewById(R.id.button2);
- Button btnCancel = (Button) dialog.findViewById(R.id.button1);
- judul.setText("Konfirmasi");
- isi.setText("Apakah anda yakin akan menghapus semua data?");
- dialog.show();
- }
- });
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- switch(id) {
- case android.R.id.home :
- this.finish();
- Intent i = new Intent(Pengaturan.this, MainActivity.class);
- startActivity(i);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @Override
- public void onBackPressed() {
- this.finish();
- Intent i = new Intent(Pengaturan.this, MainActivity.class);
- startActivity(i);
- super.onBackPressed();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement