Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.mycalc;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import static java.lang.Integer.parseInt;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // Connect button
- Button calcButton = findViewById(R.id.calcButton);
- calcButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- // Initialize text-fields
- EditText assignmentOneInput = findViewById(R.id.assignmentOne);
- // Convert integers to strings
- int fieldOne = Integer.parseInt(assignmentOneInput.getText().toString());
- // Form validation
- if (!TextUtils.isEmpty(assignmentOneInput.getText().toString()) || fieldOne>100)) {
- assignmentOneInput.setError("Please enter a number between 0 and 100.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement