开发者

EditText does not return expected value

Following is the layout xml :

<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"
  开发者_StackOverflow中文版          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>

I am trying to get the value of EditText. Default value of edit text is Enter SKU Id, I change this to some string but when using following code it still gives me the default string.

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

How can I get the current value?


Get the current String by using E11.getText().toString() is fine, the problem sould be something else.

By the way, if you want to put some hint String in EditText, use android:hint attribute instead of android:text.


Use the addTextChangedListener() method on your EditText and make your class implement or define an inner class implementing the TextWatcher class:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜