-2

Trying to read input and then display it in textview and utilize that user input. I am not sure how to read user input and use that input it could be string or number or numberdecimal type. *

<EditView
        android:id="@+id/editText1"
        android:layout_width="368sp"
        android:layout_height="35sp"
        android:layout_marginTop="73dp"
        android:background="#9E9E9E"
        android:hint="Enter Initial Bill Total"
        android:gravity="center_vertical|center_horizontal"
        android:ems="10"
        android:inputType="numberDecimal"
        android:textSize="32dp"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_marginTop="110dp"
        app:layout_constraintTop_toBottomOf="@+id/editText1"
        android:layout_marginLeft="163dp"
        app:layout_constraintLeft_toLeftOf="parent" />

* *

public class MainActivity extends AppCompatActivity {
    double d;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void display(int score) {
        EditText mEdit   = (EditText)findViewById(R.id.editText1);
        String value = mEdit.getText().toString();
        d = Double.parseDouble(value);
    }
    private void displaytext(double number) {
        TextView quantityTextView = (TextView) findViewById(R.id.textView);
        quantityTextView.setText("" + number);
    }
}

*

Ocyrus
  • 3
  • 3
  • Can you please be more specific !, You didn't even call that methods and there is score parameter which has no use. – maysara Jun 11 '17 at 00:53

2 Answers2

0

Try to obtain the text value of the double number before set text in the textview.

Anyway, you should add the error messages from Android.

Carmen
  • 181
  • 7
0

Firstly your app's xml should have used EditText instead of EditView widget that is the reason your app was crashed and you are not triggered the display method, I could suggest that add one button to the bottom of the layout and try to trigger display method by it.

aydinugur
  • 1,208
  • 2
  • 14
  • 21
  • I realized that. Appreciate it. Still have not figured out how to read users decimal input and store in variable. – Ocyrus Jun 11 '17 at 00:49
  • Cannot read user's input directly from number (i.e int, double) but you can read as **Text** and convert it what you need to get before store it, hope this is clear. – aydinugur Jun 11 '17 at 00:54