2011-04-13 163 views
0

以下是布局的xml:的EditText没有返回预期值

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/T1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:stretchColumns="0,1,2"> 
    <TableRow> 
     <EditText android:text="Enter SKU Id" 
      android:id="@+id/E1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </EditText> 
     <Button android:text="Search" 
      android:id="@+id/B1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </Button> 
    </TableRow> 
</TableLayout> 

我想获得的EditText值。编辑文本的默认值是输入SKU Id,我将其更改为一些字符串,但使用下面的代码时仍然给我默认字符串。

E11 = (EditText) findViewById(R.id.E1); 
sku = E11.getText().toString(); 

如何获取当前值?

回答

0

使用您的EditText的addTextChangedListener()方法,让你的类实现或定义一个内部类实现TextWatcher类:

1

使用E11.getText().toString()优良获取当前字符串,问题是前人的精力别的东西。

顺便说一句,如果你想把一些提示字符串放在EditText,使用android:hint属性,而不是android:text