android programing

nyrmm11
timer Asked: Apr 6th, 2018

Question Description

Hello



I have a defficiclty to understand this android code. In fact, I need to build an apk for it, so can you help me on this.



# define an xml file that fits with code in order to make the app work appropriately.



# a functional all for this code..



============================ the code==========



import android.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;





public class MainActivity extends AppCompatActivity {





private int cartCount=0;
private int totalPrice=0;






@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.main, menu);
return true;
}





public void AddBaby(View view) {
TextView editText = (TextView) findViewById(R.id.tvBDPrice);
int price = Integer.parseInt(editText.getText().toString());
totalPrice = totalPrice + price;





TextView tvCartCount = (TextView) findViewById(R.id.tvTotal);
cartCount = cartCount + 1;
tvCartCount.setText(String.valueOf(cartCount));
}





public void AddJunior(View view){
TextView editText = (TextView) findViewById(R.id.tvJDPrice);
int price = Integer.parseInt(editText.getText().toString());
totalPrice = totalPrice+price;





TextView tvCartCount= (TextView) findViewById(R.id.tvTotal);
cartCount=cartCount+1;
tvCartCount.setText(String.valueOf(cartCount));
}





public void AddAdult(View view)
{
TextView editText = (TextView) findViewById(R.id.tvADPrice);
int price = Integer.parseInt(editText.getText().toString());
totalPrice = totalPrice+price;





TextView tvCartCount= (TextView) findViewById(R.id.tvTotal);
cartCount=cartCount+1;
tvCartCount.setText(String.valueOf(cartCount));
}
public void CheckOut(View view)
{
if (cartCount==0)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Please add atleast one item to the cart before checkout")
.setTitle ("Empty cart");
AlertDialog alert= builder.create();
alert.show();
}
else
{
EditText editText= (EditText) findViewById(R.id.etShipping);
String shippingInfo= editText.getText().toString();





AlertDialog.Builder builder= new AlertDialog.Builder(this);
builder.setMessage("You have purched" + cartCount + "Item.\nTotal price:"+ totalPrice + ".\nShipping Instruction:"+ shippingInfo+ ".")
.setTitle("Checkout Sucess");





AlertDialog alert=builder.create();
alert.show();
}
}
public int getCartCount(){
return cartCount;
}
public void setCartCount(int cartCount)
{
this.cartCount=cartCount;
}





public int getTotalPrice() {
return totalPrice;
}





public void setTotalPrice(int totalPrice) {
this.totalPrice = totalPrice;
}
}



=========================== the end of the code=========



User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Similar Content

Related Tags

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors