2016-08-19 45 views
0

我正在尝试构建计算提示和遇到问题的第一个简单应用程序。 如何隐藏编辑文本中的文本,但仍然使用其功能

<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" 
    /> 

和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) { 

    } 
}; 

我有一个TextView和EditText上,两者彼此重叠。一个用于支付账单金额,另一个用于以数字格式显示该号码。

例如,如果我将100放在编辑文本中,它应该显示$ 1.00,实际上它是。但问题是,由于有两个文本视图,所以都显示数字,结果两个视图重叠,彼此阻塞每个视图。

如何隐藏多个编辑文本但仍能够使用编辑视图?

+0

什么你在这个EditText和TextView上使用的布局是什么?你能否复制整个布局,即XML UI设计文件。 –

回答

1

你可以尝试设置它的颜色为透明的,因此它不再可见

0

您可以将编辑文本中的值保存在临时变量中,并清除editText并使用该值填充TextView。

为什么你想对同一个值使用两个单独的视图元素?如果用户输入“1000”,你可以处理它并重置价值“$ 1,000.00”(或你想要的...)

相关问题