0
I wanted to make a magic square, where I put 9 numbers, and the sum of them has to result 15 (diagonals, horizontal and vertical) I’m doing in android studio . I only have this until then:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;
import static java.lang.Double.parseDouble;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText ET1 = (EditText) findViewById(R.id.ET1);
final EditText ET2 = (EditText) findViewById(R.id.ET2);
final EditText ET3 = (EditText) findViewById(R.id.ET3);
final EditText ET4 = (EditText) findViewById(R.id.ET4);
final EditText ET5 = (EditText) findViewById(R.id.ET5);
final EditText ET6 = (EditText) findViewById(R.id.ET6);
final EditText ET7 = (EditText) findViewById(R.id.ET7);
final EditText ET8 = (EditText) findViewById(R.id.ET8);
final EditText ET9 = (EditText) findViewById(R.id.ET9);
Button BT1 = (Button) findViewById(R.id.BT1);
Button BT2 = (Button) findViewById(R.id.BT2);
BT2.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
ET1.setText("");
ET2.setText("");
ET3.setText("");
ET4.setText("");
ET5.setText("");
ET6.setText("");
ET7.setText("");
ET8.setText("");
ET9.setText("");
}
return false;
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.diego.teste.MainActivity">
<Button
android:id="@+id/BT2"
android:layout_width="118dp"
android:layout_height="66dp"
android:layout_marginBottom="20dp"
android:layout_marginEnd="28dp"
android:text="@string/limpa"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="MissingConstraints"
android:layout_marginRight="28dp" />
<Button
android:id="@+id/BT1"
android:layout_width="113dp"
android:layout_height="66dp"
android:layout_marginBottom="20dp"
android:layout_marginStart="40dp"
android:text="@string/verifica"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"
android:layout_marginLeft="40dp" />
<EditText
android:id="@+id/ET1"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
android:shadowColor="@android:color/background_light"
app:layout_constraintBottom_toTopOf="@+id/ET4"
app:layout_constraintEnd_toStartOf="@+id/ET2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/ET2"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="number"
android:shadowColor="@android:color/background_light"
app:layout_constraintBottom_toTopOf="@+id/ET5"
app:layout_constraintEnd_toStartOf="@+id/ET3"
app:layout_constraintStart_toEndOf="@+id/ET1"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/ET3"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/ET6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/ET2"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/ET4"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/ET7"
app:layout_constraintEnd_toStartOf="@+id/ET5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ET1"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/ET5"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/ET8"
app:layout_constraintEnd_toStartOf="@+id/ET6"
app:layout_constraintHorizontal_bias="0.526"
app:layout_constraintStart_toEndOf="@+id/ET4"
app:layout_constraintTop_toBottomOf="@+id/ET2"
app:layout_constraintVertical_bias="0.529"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/ET6"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toTopOf="@+id/ET9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/ET5"
app:layout_constraintTop_toBottomOf="@+id/ET3"
app:layout_constraintVertical_bias="0.428"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/ET7"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="194dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ET8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ET4"
app:layout_constraintVertical_bias="1.0"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/ET8"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="190dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ET9"
app:layout_constraintStart_toEndOf="@+id/ET7"
app:layout_constraintTop_toBottomOf="@+id/ET5"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/ET9"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginBottom="194dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/ET8"
app:layout_constraintTop_toBottomOf="@+id/ET6"
tools:ignore="MissingConstraints" />
Someone can help me , in the part of taking numbers of variables, sum and check?
someone can help me , in the removal of numbers of the variables, sum and check?
– Diego Noldin
The sum of each diagonal, line and column must give
15
that’s it ?– Isac
It’s like a riddle, the goal of anyone who tries is that all directions the sum is 15. ai has a check button that says whether it is correct or n ; and the clean button for all edittext.() the clean button I’ve already made
– Diego Noldin