Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.piotr.aplikacja;
- import android.content.ContentValues;
- import android.content.Intent;
- import android.database.Cursor;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class Edytowanie extends AppCompatActivity {
- EditText title, author,price;
- Button edytuj;
- BookDbAdapter bookDbAdapter;
- String titleEdit;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_edytowanie);
- title = (EditText)findViewById(R.id.editText);
- author = (EditText)findViewById(R.id.editText5);
- price = (EditText)findViewById(R.id.editText6);
- edytuj = (Button)findViewById(R.id.button4);
- //pobranie id do edycji
- Bundle extra = getIntent().getExtras();
- titleEdit = extra.getString("TitleEdytowanie");
- Toast.makeText(getApplicationContext(),titleEdit,Toast.LENGTH_SHORT).show();
- bookDbAdapter =new BookDbAdapter(getApplicationContext());
- bookDbAdapter.open();
- Cursor cursor = bookDbAdapter.getBook(titleEdit);
- while(cursor.moveToNext()){
- title.setText(cursor.getString(1));
- author.setText(cursor.getString(2));
- price.setText(String.valueOf(cursor.getInt(3)));
- }
- edytuj.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- ContentValues newValues = new ContentValues();
- newValues.put(BookDbAdapter.TITLE, title.getText().toString());
- newValues.put(BookDbAdapter.AUTHOR, author.getText().toString());
- newValues.put(BookDbAdapter.PRICE, price.getText().toString());
- bookDbAdapter.updateBook(titleEdit,newValues);
- bookDbAdapter.close();
- startActivity(new Intent(Edytowanie.this,MainActivity.class));
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement