Hye, my problem is to rewrite if the user put the same nameItem that will change the price and the quantityItem, if not the item will add new id. i also do auto increment on id.
My Database :
This is how i try but when the name == nameItem can't read and run on else in on DataChange.
if(i != 0){
for(id1 = 1; id1<=i; id1++){
if(id1 != 0){
final DatabaseReference reff1 = FirebaseDatabase.getInstance().getReference().child("CartList").child(userID).child(String.valueOf(id1));
reff1.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
String carinama = dataSnapshot.child("nameItem").getValue().toString();
String changequantity = dataSnapshot.child("quantityItem").getValue().toString();
if(nameItem == carinama) {
int calcQuantity = Integer.parseInt(cdtb.getQuantityItem());
newpositionItem = newpositionItem + calcQuantity;
String x = String.valueOf(newpositionItem);
cdtb.setQuantityItem(x);
int price1Item = Integer.parseInt(priceItem);
newpositionItem = newpositionItem * price1Item;
cdtb.setPriceItem(d2f.format(newpositionItem));
reff1.setValue(cdtb);
id1 = i;
}else {
int calcQuantity = Integer.parseInt(changequantity);
newpositionItem = newpositionItem + calcQuantity;
String x = String.valueOf(newpositionItem);
cdtb.setQuantityItem(x);
double price1Item = Double.parseDouble(priceItem);
newpositionItem = newpositionItem * price1Item;
cdtb.setPriceItem(d2f.format(newpositionItem));
reff1.setValue(cdtb);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Toast.makeText(getContext(), ""+databaseError, Toast.LENGTH_SHORT).show();
}
});
}else {
}
}
}else{
cdtb.setImageItem(imageUrl);
cdtb.setNameItem(nameItem);
cdtb.setPriceItem(d2f.format(calcPrice));
cdtb.setSpecification(specItem);
cdtb.setQuantityItem(positionItem);
reff.child(String.valueOf(++maxid)).setValue(cdtb);
}
Thank you...
nameItem and carinama is String
in java to compare two string you must use equals method not "=="
because == will compare object location in memory and not the content string
so you code condition will be
if(nameItem.equals(carinama)){
//your code here
}
Related
I'm using GraphView library. My code below gets data from Firebase real-time database and updates the graph with values from database, but it isn't sorted. I need it to be sorted in ascending order in X axis. The data in X axis is Long type, then it's converted to date.
I've tried adding dp[index] to array list and using different sorting methods, but nothing seems to work.
#Override
public void onStart() {
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
FirebaseAuth auth;
auth = FirebaseAuth.getInstance();
FirebaseUser user = auth.getCurrentUser();
String id = user.getUid();
DataPoint[] dp = new DataPoint[(int) snapshot.child(id).getChildrenCount()];
int index = 0;
for(DataSnapshot myDataSnapshot : snapshot.child(id).getChildren()){
PointValue pointValue = myDataSnapshot.getValue(PointValue.class);
dp[index] = new DataPoint(pointValue.getxValue(), pointValue.getyValue());
index ++;
}
lineGraphSeries.resetData(dp);
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
super.onStart();
}
AlertDialog, where data is being written to the database:
builder.setPositiveButton("ADD",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if(TextUtils.isEmpty(weightEditText.getText().toString()) || TextUtils
.isEmpty(dateEditText.getText().toString())) {
Toast.makeText(getActivity(),"Please provide weight and date",
Toast.LENGTH_SHORT).show();
} else{
linearLayout.addView(createNewTextView(weightEditText.getText().toString(),
dateEditText.getText().toString()));
String id = user.getUid();
String randomId = reference.push().getKey();
try {
Date date = sdf.parse(dateEditText.getText().toString());
long x = date.getTime();
int y = Integer.parseInt(weightEditText.getText().toString());
PointValue pointValue = new PointValue(x,y);
reference.child(id).child(randomId).setValue(pointValue);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
});
builder.setView(view);
builder.show();
PointValue class:
public class PointValue {
long xValue;
int yValue;
public PointValue() {
}
public PointValue(long xValue, int yValue) {
this.xValue = xValue;
this.yValue = yValue;
}
public long getxValue() {
return xValue;
}
public int getyValue() {
return yValue;
}
}
#EDIT
Thanks to #Frank van Puffelen, I've managed to sort my data from Firebase Database using orderByChild()
https://firebase.google.com/docs/database/android/lists-of-data#sort_data
below working solution:
#Override
public void onStart() {
FirebaseAuth auth;
auth = FirebaseAuth.getInstance();
FirebaseUser user = auth.getCurrentUser();
String id = user.getUid();
Query dateAscendingOrder = database.getReference("users")
.child(id).orderByChild("xValue");
dateAscendingOrder.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
DataPoint[] dp = new DataPoint[(int) snapshot.getChildrenCount()];
int index = 0;
for (DataSnapshot myDataSnapshot : snapshot.getChildren()){
PointValue pointValue = myDataSnapshot.getValue(PointValue.class);
dp[index] = new DataPoint(pointValue.getxValue(), pointValue.getyValue());
index++;
}
lineGraphSeries.resetData(dp);
}
I'm new to using Firebase and Android Studio and I need multiple nodes to save to a realtime database in Firebase from my android app, these include users, budgets and spending as it's an expense tracking app. I've got the user information to save under its own node but I can't figure out how to create nodes for budget and spending. The code below is what I'm having difficulty with :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_categories);
setupUIViews();
firebaseAuth = getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
btn_subCat.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(validate()){
sendUserBudgets();
Toast.makeText(Categories.this, "Completed!", Toast.LENGTH_LONG).show();
finish();
startActivity(new Intent(Categories.this, Menu.class ));
}else{
Toast.makeText(Categories.this, "Submission failed", Toast.LENGTH_LONG).show();
}
}
});
}
private void setupUIViews() {
travel_input = (EditText)findViewById(R.id.travel_input);
entertainment_input = (EditText)findViewById(R.id.entertainment_input);
fitness_input = (EditText)findViewById(R.id.fitness_input);
beauty_input = (EditText)findViewById(R.id.beauty_input);
clothes_input = (EditText)findViewById(R.id.clothes_input);
holiday_input = (EditText)findViewById(R.id.holiday_input);
food_input = (EditText)findViewById(R.id.food_input);
mobile_input = (EditText)findViewById(R.id.mobile_input);
btn_subCat = (Button)findViewById(R.id.btn_subCat);
}
private Boolean validate() {
boolean result = false;
travel_budget = Double.parseDouble(travel_input.getText().toString().trim());
entertainment_budget = Double.parseDouble(entertainment_input.getText().toString().trim());
fitness_budget = Double.parseDouble(fitness_input.getText().toString().trim());
beauty_budget = Double.parseDouble(beauty_input.getText().toString().trim());
clothes_budget = Double.parseDouble(clothes_input.getText().toString().trim());
holiday_budget = Double.parseDouble(holiday_input.getText().toString().trim());
food_budget = Double.parseDouble(food_input.getText().toString().trim());
mobile_budget = Double.parseDouble(mobile_input.getText().toString().trim());
if(travel_budget.equals(null) || entertainment_budget.equals(null) || fitness_budget.equals(null) || beauty_budget.equals(null) || clothes_budget.equals(null) || holiday_budget.equals(null) || food_budget.equals(null) ||
mobile_budget.equals(null)){
Toast.makeText(Categories.this, "Please enter all fields", Toast.LENGTH_LONG).show();
} else {
result = true;
}
return result;
}
private void sendUserBudgets() {
String currentUserID = firebaseAuth.getUid();
CategoriesDB catDb = new CategoriesDB(travel_budget, entertainment_budget, fitness_budget, beauty_budget, clothes_budget, holiday_budget, food_budget, mobile_budget);
mDatabase.child("User").child(currentUserID).child("Budgets").setValue(catDb);
}
private void validate() {
boolean result = false;
travel_budget = Double.parseDouble(travel_input.getText().toString().trim());
entertainment_budget = Double.parseDouble(entertainment_input.getText().toString().trim());
fitness_budget = Double.parseDouble(fitness_input.getText().toString().trim());
beauty_budget = Double.parseDouble(beauty_input.getText().toString().trim());
clothes_budget = Double.parseDouble(clothes_input.getText().toString().trim());
holiday_budget = Double.parseDouble(holiday_input.getText().toString().trim());
food_budget = Double.parseDouble(food_input.getText().toString().trim());
mobile_budget = Double.parseDouble(mobile_input.getText().toString().trim());
if(travel_budget.equals(null) || entertainment_budget.equals(null) || fitness_budget.equals(null) || beauty_budget.equals(null) || clothes_budget.equals(null) || holiday_budget.equals(null) || food_budget.equals(null) ||
mobile_budget.equals(null)){
Toast.makeText(Categories.this, "Please enter all fields", Toast.LENGTH_LONG).show();
} else {
sendUserBudgets(travel_budget, fitness_budget, beauty_budget, clothes_budget, holiday_budget, food_budget, mobile_budget);
}
}
private void sendUserBudgets(double travel_budget, double fitness_budget, double beauty_budget, double clothes_budget, double holiday_budget, doublefood_budget, double mobile_budget) {
String currentUserID = firebaseAuth.getUid();
CategoriesDB catDb = new CategoriesDB(travel_budget, entertainment_budget, fitness_budget, beauty_budget, clothes_budget, holiday_budget, food_budget, mobile_budget);
mDatabase.child("User").child(currentUserID).child("Budgets").setValue(catDb);
}
Here once you have obtained all the user inputs and have done all the validations, you need to call the function sendUserBudgets() to save it to the database.
I have firebase database in my android project which contains three values: code, email, date. I am using switchcompat for counting present students in the firebase database. When switch will be checked, data will enter into the firebase database checking if the email is uniqe in the specific date. When switch will be unchecked, that current date's data will be removed. But my problem is that for the first time when I check the switch, it works fine. And in the second time after unchecking the switch once, when I check it once again, it enters data into firebase but also remove it automatically immediately even switch is still checked. I don't understand where is the problem in my code.
I am providing my code in the below for working of SwitchCompat.
Here is the code:
switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Date c = Calendar.getInstance().getTime();
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
final String date = df.format(c);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
final String previousDate = df.format(cal.getTime());
final int[] i = {0};
if (switch1.isChecked()) {
Query equery = present.orderByChild("email").equalTo(email);
equery.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
if (!dataSnapshot.exists()) {
String code = "1";
PresentStu presentStu = new PresentStu(FirebaseAuth.getInstance().getCurrentUser().getEmail(), date, code);
String uploadId = present.push().getKey();
present.child(uploadId).setValue(presentStu);
} else {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
String eemail = snapshot.child("email").getValue().toString();
String ddate = snapshot.child("date").getValue().toString();
if (eemail.equals(eemail) && ddate.equals(date)) {
i[0]++;
break;
}
}
// Toast.makeText(User.this,""+i[0]+"",Toast.LENGTH_SHORT).show();
if (i[0] < 1){
String code = "1";
PresentStu presentStu = new PresentStu(FirebaseAuth.getInstance().getCurrentUser().getEmail(), date, code);
String uploadId = present.push().getKey();
present.child(uploadId).setValue(presentStu);
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
} else {
Query equery = present.orderByChild("email").equalTo(email);
equery.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
String eemail = snapshot.child("email").getValue().toString();
String ddate = snapshot.child("date").getValue().toString();
if (eemail.equals(eemail) && ddate.equals(previousDate)) {
present.child(dataSnapshot.getChildren().iterator().next().getKey()).child("code").setValue("0");
}
if (eemail.equals(eemail) && ddate.equals(date)) {
snapshot.getRef().removeValue();
break;
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
});
Please, help me to find out the lacking in my code.
My database structure
Because I do not know the structure of you database, you can't simply copy/paste this snippet; it is your own code with the event listeners removed.
Get the right path to your snapshot with the right and make the change directly, without waiting for a data change.
switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Date c = Calendar.getInstance().getTime();
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
final String date = df.format(c);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
final String previousDate = df.format(cal.getTime());
final int[] i = {0};
if (switch1.isChecked()) {
Query equery = present.orderByChild("email").equalTo(email);
// TODO Change this:
DataSnapshot dataSnapshot = equery.doSomethingToGettheSnapshot()
if (!dataSnapshot.exists()) {
String code = "1";
PresentStu presentStu = new PresentStu(FirebaseAuth.getInstance().getCurrentUser().getEmail(), date, code);
String uploadId = present.push().getKey();
present.child(uploadId).setValue(presentStu);
} else {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
String eemail = snapshot.child("email").getValue().toString();
String ddate = snapshot.child("date").getValue().toString();
if (eemail.equals(eemail) && ddate.equals(date)) {
i[0]++;
break;
}
}
// Toast.makeText(User.this,""+i[0]+"",Toast.LENGTH_SHORT).show();
if (i[0] < 1){
String code = "1";
PresentStu presentStu = new PresentStu(FirebaseAuth.getInstance().getCurrentUser().getEmail(), date, code);
String uploadId = present.push().getKey();
present.child(uploadId).setValue(presentStu);
}
}
}
} else {
Query equery = present.orderByChild("email").equalTo(email);
// TODO Change this:
DataSnapshot dataSnapshot = equery.doSomethingToGettheSnapshot()
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
String eemail = snapshot.child("email").getValue().toString();
String ddate = snapshot.child("date").getValue().toString();
if (eemail.equals(eemail) && ddate.equals(previousDate)) {
present.child(dataSnapshot.getChildren().iterator().next().getKey()).child("code").setValue("0");
}
if (eemail.equals(eemail) && ddate.equals(date)) {
snapshot.getRef().removeValue();
break;
}
}
}
}
}
});
So I have been trying to implement a way to check if the user had already sent a friend a request to the profile visited, or if the user has received a friend request from the profile visited. Based on the results, the buttons will be set to sent request, accept request ,add friend or friends
However, in my Firebase function, the first 3 if statements aren't met, even if one of them was supposed to be met. The first else if statement should have worked because I already sent a friend request to the profile visited.
When I ran a debug, it shows something like value = {sentFriendRequests={jmarston=2}}. So Firebase knows that I added John Marston as a friend, but for some reason the else if statement wasn't working. Its the else statement that works instead
My code is down below:
checkFriendRequestStatus function
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID) {
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class) == strVisitedUID) {
buttonsCallback.setButtonStatus(1, 1);
}
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class) == strVisitedUID) {
buttonsCallback.setButtonStatus(1, 2);
}
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class) == strVisitedUID) {
buttonsCallback.setButtonStatus(1, 3);
}
else {
buttonsCallback.setButtonStatus(1, 4);;
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
onViewCreated function
#Override
public void onViewCreated(View view, Bundle savedInstanceState){
sRFullName = (TextView) view.findViewById(R.id.sRUFullNameET);
addFriendBtn = (Button) view.findViewById(R.id.sRUAddFriendBtn);
sentRequestBtn = (Button) view.findViewById(R.id.sRUFriendReqSentBtn);
acceptRequestBtn = (Button) view.findViewById(R.id.sRUAcceptRequestBtn);
wereFriendsBtn = (Button) view.findViewById(R.id.sRUWeFriendsBtn);
final String strVisitedUserID = getArguments().getString("sRUserID");
final String visitedUsername = getArguments().getString("sRUsername");
ShPreference = getActivity().getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
// converts Stringed userID back to Int
final String strSignedInUID = ShPreference.getInt(currentUserID, 0) + "";
final String signedInUsername = ShPreference.getString(currentUsername, "");
// converts the userSignedIn id to string
//final String strSignedInUID = userSignedInID + "";
// checks if the current User visited has been sent a friend Request
checkFriendRequestStatus(new ButtonStatus() {
#Override
public void setButtonStatus(int choice, int button) {
/**
* The choice params is for the choose if to show or hide buttons.
* The buttons params selects which buttons are to show or hide
*/
addFriendBtn.setVisibility(View.GONE);
sentRequestBtn.setVisibility(View.GONE);
acceptRequestBtn.setVisibility(View.GONE);
wereFriendsBtn.setVisibility(View.GONE);
// if choosed to show buttons
if (choice == 1) {
// show buttons depending on the friendRequest status
if (button == 1) {
wereFriendsBtn.setVisibility(View.VISIBLE);
}
else if (button == 2) {
sentRequestBtn.setVisibility(View.VISIBLE);
}
else if (button == 3) {
acceptRequestBtn.setVisibility(View.VISIBLE);
}
else {
addFriendBtn.setVisibility(View.VISIBLE);
}
}
}
}, strSignedInUID, visitedUsername, strVisitedUserID);
// sets the name with the Full Name; called from SearchResultsAdapter
sRFullName.setText(getArguments().getString("sRFullName"));
}
To compare String object use equals instead of == (double equals). Double equals will compare reference not their values.
Update your code of comparison like below:
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID) {
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class).equals(strVisitedUID)) {
buttonsCallback.setButtonStatus(1, 1);
}
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class).equals(strVisitedUID)) {
buttonsCallback.setButtonStatus(1, 2);
}
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class).equals(strVisitedUID)) {
buttonsCallback.setButtonStatus(1, 3);
}
else {
buttonsCallback.setButtonStatus(1, 4);;
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
i get error when i want to check empty value in edittext that I create. It become error to my source code
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String code = etCode.getText().toString();
String name = etName.getText().toString();
float price = Float.parseFloat(etPrice.getText().toString());
int qty = Integer.parseInt(etQty.getText().toString());
if(code.length() != 0 && name.length() != 0 && price.length() != 0 && qty.length() != 0){
myDB.addData(code, name, price, qty);
etCode.setText("");
etName.setText("");
etPrice.setText("");
etQty.setText("");
}else{
Toast.makeText(MainActivity.this,"You must put something in the text field!",Toast.LENGTH_LONG).show();
}
}
});
How to solve my problem ?
try using
TextUtils.isEmpty(editText.getText().toString());
normally you can never have a null come out of a text field but you check if its empty with the above line. so both "" and null will give you back a true
I believe your error java.lang.NumberFormatException: Invalid float: ""
that is because you are trying to convert empty value to float.
you can do as follow.
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String code = etCode.getText().toString();
String name = etName.getText().toString();
String price = etPrice.getText().toString();
String qty = etQty.getText().toString();
if(code.isEmpty() && name.isEmpty() && price.isEmpty() && qty.isEmpty(){
float price1 = Float.parseFloat(etPrice.getText().toString());
int qty1 = Integer.parseInt(etQty.getText().toString());
myDB.addData(code, name, price1, qty1);
etCode.setText("");
etName.setText("");
etPrice.setText("");
etQty.setText("");
}else{
Toast.makeText(MainActivity.this,"You must put something in the text field!",Toast.LENGTH_LONG).show();
}
}
});
Use the
if (TextUtils.isEmpty(edittext.getText().toString()) {
Log.d("ERROR","Edittext is empty");
}
You can check that way
if(etCode.getText().toString().trim().equalsIgnoreCase(""))
{
// etCode edittext is empty
}
Try this
/*
* for checking String valid or not
*/
public boolean validateString(String data) {
return (data != null && !data.isEmpty() && data.length() > 0 && !data.equals("null"));
}
if(validateString(edittext.getText().toString()){
//Valid String
}
Try this:
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String code = etCode.getText().toString();
String name = etName.getText().toString();
float price = Float.parseFloat(etPrice.getText().toString());
int qty = Integer.parseInt(etQty.getText().toString());
if(code.length() != 0 && name.length() != 0 && price != 0 && qty != 0){
myDB.addData(code, name, price, qty);
etCode.setText("");
etName.setText("");
etPrice.setText("");
etQty.setText("");
}else{
Toast.makeText(MainActivity.this,"You must put something in the text field!",Toast.LENGTH_LONG).show();
}
}
});
You can try like this:
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String code = etCode.getText().toString();
String name = etName.getText().toString();
String priceStr = etPrice.getText().toString();
String qtyStr = etQty.getText().toString();
float price;
int qty;
if(code.length()==0) {
Toast.makeText(MainActivity.this,"Your code is empty!",Toast.LENGTH_LONG).show();
}
if(name.length()==0) {
Toast.makeText(MainActivity.this,"Your name is empty!",Toast.LENGTH_LONG).show();
}
if(priceStr.length()==0) {
Toast.makeText(MainActivity.this,"Your price is empty!",Toast.LENGTH_LONG).show();
}else {
try {
price = Float.parseFloat(priceStr);
}catch (Exception e) {
Toast.makeText(MainActivity.this,"Your price is not valid!",Toast.LENGTH_LONG).show();
}
}
if(qtyStr.length()==0) {
Toast.makeText(MainActivity.this,"Your qty is empty!",Toast.LENGTH_LONG).show();
}else {
try {
qty = Integer.parseInt(qtyStr);
}catch (Exception e) {
Toast.makeText(MainActivity.this,"Your qty is not valid!",Toast.LENGTH_LONG).show();
}
}
myDB.addData(code, name, price, qty);
etCode.setText("");
etName.setText("");
etPrice.setText("");
etQty.setText("");
}
});