Updated the layout for Part2
This commit is contained in:
@@ -27,7 +27,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return insets;
|
return insets;
|
||||||
});
|
});
|
||||||
|
|
||||||
TextInputLayout tempInput = findViewById(R.id.inputTemp);
|
TextInputLayout tempInput = findViewById(R.id.inputLayoutTemp);
|
||||||
Button CtoF = findViewById(R.id.but_cToF);
|
Button CtoF = findViewById(R.id.but_cToF);
|
||||||
Button FtoC = findViewById(R.id.but_fToC);
|
Button FtoC = findViewById(R.id.but_fToC);
|
||||||
Button reset = findViewById(R.id.but_reset);
|
Button reset = findViewById(R.id.but_reset);
|
||||||
@@ -37,7 +37,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
assert tempInput.getEditText() != null;
|
tempInput.setError(null);
|
||||||
|
if (tempInput.getEditText() == null) return;
|
||||||
String userInput = tempInput.getEditText().getText().toString().trim();
|
String userInput = tempInput.getEditText().getText().toString().trim();
|
||||||
if(userInput.isEmpty()) {
|
if(userInput.isEmpty()) {
|
||||||
tempInput.setError("Please enter a temperature");
|
tempInput.setError("Please enter a temperature");
|
||||||
@@ -50,7 +51,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
result.setText(resultString);
|
result.setText(resultString);
|
||||||
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// Handle cases where the input is not a valid decimal number
|
|
||||||
tempInput.setError("Invalid number format");
|
tempInput.setError("Invalid number format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
assert tempInput.getEditText() != null;
|
tempInput.setError(null);
|
||||||
|
if (tempInput.getEditText() == null) return;
|
||||||
String userInput = tempInput.getEditText().getText().toString().trim();
|
String userInput = tempInput.getEditText().getText().toString().trim();
|
||||||
if(userInput.isEmpty()) {
|
if(userInput.isEmpty()) {
|
||||||
tempInput.setError("Please enter a temperature");
|
tempInput.setError("Please enter a temperature");
|
||||||
@@ -83,6 +84,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
result.setText("");
|
result.setText("");
|
||||||
|
if (tempInput.getEditText() != null) {
|
||||||
|
tempInput.getEditText().setText("");
|
||||||
|
}
|
||||||
|
tempInput.setError(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,97 +3,130 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/main"
|
android:id="@+id/main"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:textAlignment="center"
|
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<TextView
|
<Button
|
||||||
android:id="@+id/result"
|
android:id="@+id/but_calc"
|
||||||
android:layout_width="109dp"
|
android:layout_width="153dp"
|
||||||
android:layout_height="28dp"
|
android:layout_height="39dp"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="32dp"
|
||||||
android:layout_marginTop="28dp"
|
android:backgroundTint="#A9A7A7"
|
||||||
android:textSize="20sp"
|
android:text="Calculate"
|
||||||
app:layout_constraintStart_toEndOf="@+id/text_conversion"
|
android:textColor="#FFFFFF"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/inputTemp" />
|
app:cornerRadius="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/but_reset"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/but_reset"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/but_reset"
|
||||||
|
app:layout_constraintVertical_bias="0.0" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView2"
|
android:id="@+id/textView2"
|
||||||
android:layout_width="410dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="44dp"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
android:text="Temperature Conversion"
|
android:text="Temperature Conversion"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:layout_editor_absoluteX="8dp" />
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_Temp"
|
android:id="@+id/text_Temp"
|
||||||
android:layout_width="128dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
android:lineSpacingExtra="10sp"
|
|
||||||
android:text="Temperature:"
|
android:text="Temperature:"
|
||||||
android:textAlignment="center"
|
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:typeface="sans"
|
app:layout_constraintBottom_toBottomOf="@+id/inputLayoutTemp"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView2" />
|
app:layout_constraintTop_toTopOf="@+id/inputLayoutTemp" />
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:layout_width="408dp"
|
android:id="@+id/inputLayoutTemp"
|
||||||
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:layout_marginTop="16dp"
|
||||||
tools:layout_editor_absoluteY="44dp">
|
app:hintEnabled="false"
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
|
||||||
android:id="@+id/inputTemp"
|
|
||||||
android:layout_width="280dp"
|
|
||||||
android:layout_height="41dp"
|
|
||||||
android:hint="Enter Temperature"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@+id/text_Temp"
|
app:layout_constraintStart_toEndOf="@+id/text_Temp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView2" />
|
app:layout_constraintTop_toBottomOf="@+id/textView2">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/inputTemp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Enter Temperature"
|
||||||
|
android:textColorHint="#9E9E9E"
|
||||||
|
android:inputType="numberDecimal|numberSigned" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_conversion"
|
android:id="@+id/text_conversion"
|
||||||
android:layout_width="109dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="28dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="40dp"
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
android:text="Conversion:"
|
android:text="Conversion:"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/text_Temp"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
tools:layout_editor_absoluteX="4dp" />
|
app:layout_constraintTop_toBottomOf="@+id/inputLayoutTemp" />
|
||||||
|
|
||||||
<Button
|
<TextView
|
||||||
android:id="@+id/but_cToF"
|
android:id="@+id/result"
|
||||||
android:layout_width="409dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="51dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="24dp"
|
android:layout_marginStart="8dp"
|
||||||
android:text="C to F"
|
android:layout_marginEnd="16dp"
|
||||||
android:textColorLink="#A09F9F"
|
android:textSize="20sp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/text_conversion"
|
app:layout_constraintBottom_toBottomOf="@+id/text_conversion"
|
||||||
tools:layout_editor_absoluteX="34dp" />
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/text_conversion"
|
||||||
<Button
|
app:layout_constraintTop_toTopOf="@+id/text_conversion" />
|
||||||
android:id="@+id/but_fToC"
|
|
||||||
android:layout_width="409dp"
|
|
||||||
android:layout_height="51dp"
|
|
||||||
android:text="F to C"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/but_cToF"
|
|
||||||
tools:layout_editor_absoluteX="0dp" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/but_reset"
|
android:id="@+id/but_reset"
|
||||||
android:layout_width="409dp"
|
android:layout_width="153dp"
|
||||||
android:layout_height="51dp"
|
android:layout_height="39dp"
|
||||||
|
android:layout_marginStart="36dp"
|
||||||
|
android:backgroundTint="#A9A7A7"
|
||||||
android:text="Reset"
|
android:text="Reset"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/but_fToC"
|
android:textColor="#FFFFFF"
|
||||||
tools:layout_editor_absoluteX="-13dp" />
|
app:cornerRadius="0dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
tools:layout_editor_absoluteY="307dp" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/radBut_CtoF"
|
||||||
|
style="@style/Widget.Material3.CompoundButton.RadioButton"
|
||||||
|
android:layout_width="75dp"
|
||||||
|
android:layout_height="34dp"
|
||||||
|
android:text="C to F"
|
||||||
|
tools:layout_editor_absoluteX="26dp"
|
||||||
|
tools:layout_editor_absoluteY="216dp" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/radBut_FtoC"
|
||||||
|
style="@style/Widget.Material3.CompoundButton.RadioButton"
|
||||||
|
android:layout_width="75dp"
|
||||||
|
android:layout_height="34dp"
|
||||||
|
android:text="F to C"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/radBut_CtoF"
|
||||||
|
tools:layout_editor_absoluteX="26dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txt_select"
|
||||||
|
android:layout_width="151dp"
|
||||||
|
android:layout_height="29dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:gravity="bottom"
|
||||||
|
android:text="Select Conversion:"
|
||||||
|
android:textSize="15dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/text_conversion"
|
||||||
|
tools:layout_editor_absoluteX="16dp" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user