SHARE
TWEET

Untitled

a guest Sep 19th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.zaliczenie_19_9_2019;
  2.  
  3. import android.content.ContentValues;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8.  
  9. public class Zapis extends MainActivity {
  10.     static int counter = 0;
  11.  
  12.     private Button dodaj;
  13.     private EditText nazwaTowaru;
  14.     private EditText iloscTowaru;
  15.  
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.zapis);
  20.  
  21.         dodaj = findViewById(R.id.buttonDodajDoBazy);
  22.         nazwaTowaru = findViewById(R.id.editTextNazwaTowaru);
  23.         iloscTowaru = findViewById(R.id.editTextIlosc);
  24.  
  25.         View.OnClickListener dodajDoBazy = new View.OnClickListener() {
  26.             @Override
  27.             public void onClick(View view) {
  28.                 String nazwa = nazwaTowaru.getText().toString();
  29.                 int ilosc =  Integer.parseInt(iloscTowaru.getText().toString());
  30.                 /*baza.execSQL("INSERT INTO 'towary' VALUES(" +
  31.                                 counter + "," +
  32.                                 nazwa + "," +
  33.                                 ilosc + ");");
  34.                 */
  35.                 ContentValues cv = new ContentValues();
  36.                 cv.put("idTowaru", counter);
  37.                 cv.put("nazwa", nazwa);
  38.                 cv.put("ilosc", ilosc);
  39.                 baza.insertOrThrow("towary", null, cv);
  40.                 counter++;
  41.             }
  42.         };
  43.  
  44.         dodaj.setOnClickListener(dodajDoBazy);
  45.  
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top