Advertisement
Guest User

Untitled

a guest
May 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package com.example.piotr.aplikacja;
  2.  
  3. import android.content.ContentValues;
  4. import android.content.Intent;
  5. import android.database.Cursor;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. public class Edytowanie extends AppCompatActivity {
  14.  
  15. EditText title, author,price;
  16. Button edytuj;
  17. BookDbAdapter bookDbAdapter;
  18. String titleEdit;
  19.  
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_edytowanie);
  24.  
  25. title = (EditText)findViewById(R.id.editText);
  26. author = (EditText)findViewById(R.id.editText5);
  27. price = (EditText)findViewById(R.id.editText6);
  28. edytuj = (Button)findViewById(R.id.button4);
  29. //pobranie id do edycji
  30. Bundle extra = getIntent().getExtras();
  31. titleEdit = extra.getString("TitleEdytowanie");
  32. Toast.makeText(getApplicationContext(),titleEdit,Toast.LENGTH_SHORT).show();
  33. bookDbAdapter =new BookDbAdapter(getApplicationContext());
  34. bookDbAdapter.open();
  35. Cursor cursor = bookDbAdapter.getBook(titleEdit);
  36. while(cursor.moveToNext()){
  37. title.setText(cursor.getString(1));
  38. author.setText(cursor.getString(2));
  39. price.setText(String.valueOf(cursor.getInt(3)));
  40. }
  41.  
  42. edytuj.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View view) {
  45. ContentValues newValues = new ContentValues();
  46. newValues.put(BookDbAdapter.TITLE, title.getText().toString());
  47. newValues.put(BookDbAdapter.AUTHOR, author.getText().toString());
  48. newValues.put(BookDbAdapter.PRICE, price.getText().toString());
  49. bookDbAdapter.updateBook(titleEdit,newValues);
  50. bookDbAdapter.close();
  51. startActivity(new Intent(Edytowanie.this,MainActivity.class));
  52. }
  53. });
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement