Queria fazer um quadrado magico, onde coloco 9 números, e a soma deles tem que resultar 15(nas diagonais, horizontais e verticais) estou fazendo no android studio . só tenho isso até então:
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" />
Alguém consegue me ajudar , na parte de retirada de números das variáveis, soma e verificação?
15
é isso ?