Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ViewProduct extends AppCompatActivity {
- private String edit_product_ID;
- //private String edit_product_Product;
- private String edit_product_Price;
- private EditText productView, priceView;
- private TextView mSave, mDelete;
- private FirebaseFirestore db = FirebaseFirestore.getInstance();
- private static final String KEY_PRODUCT = "product";
- private static final String KEY_PRICE = "price";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.view_product);
- Intent intent = getIntent();
- String product;
- String price;
- String id;
- id = String.valueOf(getIntent().getExtras().get("Id"));
- product = String.valueOf(getIntent().getExtras().get("Product"));
- price = String.valueOf(getIntent().getExtras().get("Price"));
- Toast.makeText(this, "The Product ID: " + id +
- " Product Name " + product + " Product Price " + price, Toast.LENGTH_LONG).show();
- EditText productView = findViewById(R.id.product);
- productView.setText(product);
- EditText priceView = findViewById(R.id.price);
- priceView.setText(price);
- mSave = (TextView) findViewById(R.id.save);
- mDelete = (TextView) findViewById(R.id.delete);
- }
- public void saveProduct(View view) {
- String product = productView.getText().toString();
- String price = priceView.getText().toString();
- Map<String, Object> product_update = new HashMap<>();
- product_update.put(KEY_PRODUCT, product);
- product_update.put(KEY_PRICE, price);
- db.collection("ultra_liquors").document().set(product_update)
- .addOnSuccessListener(new OnSuccessListener<Void>() {
- @Override
- public void onSuccess(Void aVoid) {
- Toast.makeText(ViewProduct.this, "Product saved", Toast.LENGTH_SHORT).show();
- }
- })
- .addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(@NonNull Exception e) {
- Toast.makeText(ViewProduct.this, "Not saved", Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement