Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – Text not appearing but exists, Trying to make a simple app that calculates average

Posted on November 11, 2022 By

Solution 1 :

Set height in every edittext to wrap content

eg.

 android_layout_height="wrap_content"

and set textcolor dark currently i run your layout in white background it not see any text.
so use visible color for text

Problem :

Been trying to make a simple app that can calculate the average of 8 numbers(with decimals). I already made the layout and made an initial project that adds two numbers which when i tested is working fine but when i decided to continue on my original goal, make an app that can calculate the average of 8 numbers(with decimal), a problem occured. When i tested it on my phone, i typed some numbers on the number field, it moves indicating that something is being typed but what i typed didn’t appear. At first my hunch is that the font color is white which is not, but it still doesn’t show. Please help.

my layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

<TextView
    android_id="@+id/sub"
    android_layout_width="140dp"
    android_layout_height="20dp"
    android_layout_marginStart="20dp"
    android_layout_marginLeft="20dp"
    android_layout_marginTop="10dp"
    android_editable="true"
    android_text="Subject"
    app_fontFamily="sans-serif-black"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/sub1" />

<TextView
    android_id="@+id/sub1"
    android_layout_width="140dp"
    android_layout_height="20dp"
    android_layout_marginStart="20dp"
    android_layout_marginLeft="20dp"
    android_layout_marginTop="20dp"
    android_editable="true"
    android_text="Subject"
    app_fontFamily="sans-serif-black"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toTopOf="parent" />

<TextView
    android_id="@+id/sub2"
    android_layout_width="140dp"
    android_layout_height="20dp"
    android_layout_marginStart="20dp"
    android_layout_marginLeft="20dp"
    android_layout_marginTop="10dp"
    android_editable="true"
    android_text="Subject"
    app_fontFamily="sans-serif-black"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/sub" />

<TextView
    android_id="@+id/sub4"
    android_layout_width="140dp"
    android_layout_height="20dp"
    android_layout_marginStart="20dp"
    android_layout_marginLeft="20dp"
    android_layout_marginTop="10dp"
    android_editable="true"
    android_text="Subject"
    app_fontFamily="sans-serif-black"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/sub2" />

<TextView
    android_id="@+id/sub5"
    android_layout_width="140dp"
    android_layout_height="20dp"
    android_layout_marginStart="20dp"
    android_layout_marginLeft="20dp"
    android_layout_marginTop="10dp"
    android_editable="true"
    android_text="Subject"
    app_fontFamily="sans-serif-black"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/sub4" />

<TextView
    android_id="@+id/sub6"
    android_layout_width="140dp"
    android_layout_height="20dp"
    android_layout_marginStart="20dp"
    android_layout_marginLeft="20dp"
    android_layout_marginTop="10dp"
    android_editable="true"
    android_text="Subject"
    app_fontFamily="sans-serif-black"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/sub5" />

<TextView
    android_id="@+id/sub7"
    android_layout_width="140dp"
    android_layout_height="20dp"
    android_layout_marginStart="20dp"
    android_layout_marginLeft="20dp"
    android_layout_marginTop="10dp"
    android_editable="true"
    android_text="Subject"
    app_fontFamily="sans-serif-black"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/sub6" />

<TextView
    android_id="@+id/sub8"
    android_layout_width="140dp"
    android_layout_height="20dp"
    android_layout_marginStart="20dp"
    android_layout_marginLeft="20dp"
    android_layout_marginTop="10dp"
    android_editable="true"
    android_text="Subject"
    app_fontFamily="sans-serif-black"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/sub7" />

<EditText
    android_id="@+id/num"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="30dp"
    android_layout_marginLeft="30dp"
    android_layout_marginTop="20dp"
    android_editable="true"
    android_ems="10"
    android_inputType="numberDecimal"
    android_textColor="#00FF0000"
    app_layout_constraintStart_toEndOf="@+id/sub1"
    app_layout_constraintTop_toTopOf="parent" />

<EditText
    android_id="@+id/num1"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="30dp"
    android_layout_marginLeft="30dp"
    android_layout_marginTop="10dp"
    android_ems="10"
    android_inputType="numberDecimal"
    app_layout_constraintStart_toEndOf="@+id/sub"
    app_layout_constraintTop_toBottomOf="@+id/num" />

<EditText
    android_id="@+id/num2"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="30dp"
    android_layout_marginLeft="30dp"
    android_layout_marginTop="10dp"
    android_ems="10"
    android_inputType="numberDecimal"
    app_layout_constraintStart_toEndOf="@+id/sub2"
    app_layout_constraintTop_toBottomOf="@+id/num1" />

<EditText
    android_id="@+id/num3"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="30dp"
    android_layout_marginLeft="30dp"
    android_layout_marginTop="10dp"
    android_ems="10"
    android_inputType="numberDecimal"
    app_layout_constraintStart_toEndOf="@+id/sub4"
    app_layout_constraintTop_toBottomOf="@+id/num2" />

<EditText
    android_id="@+id/num4"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="30dp"
    android_layout_marginLeft="30dp"
    android_layout_marginTop="10dp"
    android_ems="10"
    android_inputType="numberDecimal"
    app_layout_constraintStart_toEndOf="@+id/sub5"
    app_layout_constraintTop_toBottomOf="@+id/num3" />

<EditText
    android_id="@+id/num5"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="30dp"
    android_layout_marginLeft="30dp"
    android_layout_marginTop="10dp"
    android_ems="10"
    android_inputType="numberDecimal"
    app_layout_constraintStart_toEndOf="@+id/sub6"
    app_layout_constraintTop_toBottomOf="@+id/num4" />

<EditText
    android_id="@+id/num6"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="30dp"
    android_layout_marginLeft="30dp"
    android_layout_marginTop="10dp"
    android_ems="10"
    android_inputType="numberDecimal"
    app_layout_constraintStart_toEndOf="@+id/sub7"
    app_layout_constraintTop_toBottomOf="@+id/num5" />

<EditText
    android_id="@+id/num7"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="30dp"
    android_layout_marginLeft="30dp"
    android_layout_marginTop="10dp"
    android_ems="10"
    android_inputType="numberDecimal"
    app_layout_constraintStart_toEndOf="@+id/sub8"
    app_layout_constraintTop_toBottomOf="@+id/num6" />

<Button
    android_id="@+id/btnAvr"
    android_layout_width="80dp"
    android_layout_height="30dp"
    android_layout_marginStart="180dp"
    android_layout_marginLeft="180dp"
    android_layout_marginTop="12dp"
    android_text="Get Average"
    android_textSize="8sp"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/tvAnswer" />

<TextView
    android_id="@+id/tvAnswer"
    android_layout_width="60dp"
    android_layout_height="20dp"
    android_layout_marginStart="190dp"
    android_layout_marginLeft="190dp"
    android_layout_marginTop="30dp"
    android_text="Average"
    android_textSize="14sp"
    app_layout_constraintStart_toStartOf="parent"
    app_layout_constraintTop_toBottomOf="@+id/num7" />

READ  [FIXED] Include multiple directories in Android auto backup rule?
Powered by Inline Related Posts

My Java Code

package com.example.cardmkii;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private TextView sub;
private TextView sub1;
private TextView sub2;
private TextView sub4;
private TextView sub5;
private TextView sub6;
private TextView sub7;
private TextView sub8;
private EditText numb;
private EditText numb1;
private EditText numb2;
private EditText numb3;
private EditText numb4;
private EditText numb5;
private EditText numb6;
private EditText numb7;
private Button average;
private TextView result;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    sub = (TextView) findViewById(R.id.sub);
    sub1 = (TextView) findViewById(R.id.sub1);
    sub2 = (TextView) findViewById(R.id.sub2);
    sub4 = (TextView) findViewById(R.id.sub4);
    sub5 = (TextView) findViewById(R.id.sub5);
    sub6 = (TextView) findViewById(R.id.sub6);
    sub7 = (TextView) findViewById(R.id.sub7);
    sub8 = (TextView) findViewById(R.id.sub8);
    numb = (EditText) findViewById(R.id.num);
    numb1 = (EditText) findViewById(R.id.num1);
    numb2 = (EditText) findViewById(R.id.num2);
    numb3 = (EditText) findViewById(R.id.num3);
    numb4 = (EditText) findViewById(R.id.num4);
    numb5 = (EditText) findViewById(R.id.num5);
    numb6 = (EditText) findViewById(R.id.num6);
    numb7 = (EditText) findViewById(R.id.num7);
    average = (Button) findViewById(R.id.btnAvr);
    result = (TextView) findViewById(R.id.tvAnswer);

    average.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            double number = Double.parseDouble(numb.getText().toString());
            double number1 = Double.parseDouble(numb1.getText().toString());
            double number2 = Double.parseDouble(numb2.getText().toString());
            double number3 = Double.parseDouble(numb3.getText().toString());
            double number4 = Double.parseDouble(numb4.getText().toString());
            double number5 = Double.parseDouble(numb5.getText().toString());
            double number6 = Double.parseDouble(numb6.getText().toString());
            double number7 = Double.parseDouble(numb7.getText().toString());
            double average = (number + number1 + number2 + number3 + number4 + number5 + number6 + number7)/8;
            result.setText("Answer: " + String.valueOf(average));

        }
    });
}

}

Android Tags:android, java

Post navigation

Previous Post: Can a beginner learn Moonlight Sonata 1st Movement?
Next Post: [FIXED] java – App keeps crashing when ListView item is clicked on

Related Posts

[FIXED] Specify Android Lint version Android
[FIXED] Kotlin mutableMap automatically changing in android? Android
[FIXED] java – onClick Sign Up method includes onClick Datepicker, how to make it work? Android
[FIXED] xaml – Xamarin Forms Center CollectionView content Android
[FIXED] java – How to start an Unity App with an Intent from another App? Android
[FIXED] android – Is there a way for loading images from local storage to the backgroundImage property of the CircleAvatar widget in Flutter? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What are the main features of Islamic education?
  • Is the Jeep 4xe worth it?
  • How does the ringer work on cast iron?
  • What is the biggest size interior door?
  • Is blue raspberry an original Jolly Rancher flavor?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme