计算器的EditText

时间:2014-04-15 15:55:24

标签: android android-edittext

我正在尝试为计算金钱的计算执行EditText。我想要一个EditText这样的" $ 0.00",当我点击按钮例如按钮1时,我不知道该怎么做,把1放在最后像是& #34; $ 0.01",以及下一个号码" $ 0.11"。

    <EditText
        android:id="@+id/etPantalla"
        android:drawableRight="@drawable/ic_launcher"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:ellipsize="end"
        android:ems="10"
        android:maxLength="8"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="right"
        android:longClickable="false"
        android:maxLines="1"
        android:singleLine="true"
        android:textSize="40sp" />

2 个答案:

答案 0 :(得分:0)

将Drawableleft属性放入edittext 例如,如果这是您的edittext

<EditText
    android:layout_below="@+id/tv_signup_descriptionError"
    android:id="@+id/et_signup_description"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dip"
    android:hint="@string/et_hint_enterDescription"
    android:singleLine="false"
    android:lines="5"
    android:gravity="top"
    android:scrollHorizontally="false"
    android:inputType="textMultiLine" 
    android:maxLines="5"
    />

加入

android:drawableLeft="@drawable/ the dollar image"

答案 1 :(得分:0)

重复:How to use EditText onTextChanged event when i press the number?

EditText money = (EditText)findViewById(R.id.my_edit_text);
money.addTextChangedListener(new TextWatcher() {

    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // do what you need here
    } 

});