Cal
Cal

Reputation: 27

how do you hide texts in edit text but still use its function

I am trying to build a first simple app for calculating tips and having trouble.

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:id="@+id/editCurrent"
    android:layout_row="0"
    android:layout_column="0"
    android:ems="10"
    android:gravity="center_horizontal"
    android:layout_columnSpan="2"
    android:padding="16dp"
    android:maxLength="6"
    android:hint="Enter the Amount"

    />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/showCurrent"
    android:padding="16dp"
    android:layout_row="0"
    android:layout_column="0"
    android:layout_columnSpan="2"
    android:gravity="center_horizontal"
    />

and for MainActivity

private final TextWatcher editCurrentWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        try {
            bill = Double.parseDouble(s.toString()) / 100;
            showCurrent.setText(currencyFormat.format(bill));
            calculate();
        }
        catch (NumberFormatException e){
            showCurrent.setText("");
            bill = 0.0;
        }
        calculate();
    }

    @Override
    public void afterTextChanged(Editable s) {

    }
};

I have a TextView and a EditText, both overlapping each other. One is for putting a bill amount and the other is for displaying that number in number format.

For example, if I put 100 in edit text, it should display $1.00 and actually it does. But the problem is that since there are two text views, both displays the number and as a result, two views are overlapping each other blocking each view.

How do I hide a number of edit text but still be able to use the edit view?

Upvotes: 0

Views: 1293

Answers (2)

Thorvald
Thorvald

Reputation: 3563

you can try to set it's color to transparent so it's not visible anymore

Upvotes: 3

Tobias Lukoschek
Tobias Lukoschek

Reputation: 405

You can save the value inside of the edit text in a temp variable and clear the editText and fill the TextView with the value.

Why do you want to use two separate view elements for the same value? If the user enter '1000' you can process it and reset the value to '$1,000.00' (or what you want...)

Upvotes: 0

Related Questions