// MainActivity Example // Source code file: MainActivity.java package it372.ssmith.groceryitem; import android.content.Intent; import android.os.Bundle; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class MainActivity extends AppCompatActivity { // Instance variables for edit text widgets private EditText edtDescription; private EditText edtCode; private EditText edtPrice; private Button btnSubmit; private TextView txtDisplay; private String groceryInfo = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); // Instantiate Widget Objects edtDescription = findViewById(R.id.edt_descr); edtCode = findViewById(R.id.edt_code); edtPrice = findViewById(R.id.edt_price); btnSubmit = findViewById(R.id.btn_submit); txtDisplay = findViewById(R.id.txt_display); // Attach event listener to button btnSubmit.setOnClickListener( v -> { String description = edtDescription.getText( ).toString( ); int code = Integer.parseInt(edtCode.getText( ).toString( )); double price = Double.parseDouble(edtPrice.getText( ).toString( )); groceryInfo += String.format("Description: %s\nCode: %d\nPrice: %.2f\n\n", description, code, price); // txtDisplay.setText(groceryInfo); // Create new activity Intent intent = new Intent(this, DisplayItemsActivity.class); intent.putExtra("ginfo", groceryInfo); startActivity(intent); }); } }