Android : EditText.getText() returns "" (Empty) String on Android 1.6
<p>I am trying to fetch the EditText value on click of a button.</p>

<pre><code>String ETValue = ((EditText)findViewById(R.id.ETID)).getText().toString().trim();
</code></pre>

<p>Every things works fine on other android versions, but on 1.6 I am getting ""(Empty) String.</p>

<p>Whats going wrong on Android 1.6, how this is happening?</p>

<p>Thanks</p>

<p>Screen Shots:</p>

<p><img src="http://i.stack.imgur.com/a09ST.png" alt="enter image description here"></p>

<p><img src="http://i.stack.imgur.com/wfnT9.png" alt="enter image description here"></p>

<p>Code Reference : </p>

<p>main.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"&gt;

        &lt;TextView 
              android:layout_marginTop="10dip" 
              android:layout_marginLeft="5dip" 
              android:text="Type you text here"  
              android:id="@+id/TextView02" 
              android:layout_height="wrap_content" 
              android:textColor="#333333" 
              android:layout_width="fill_parent" 
              android:textSize="16dip"&gt;
              &lt;/TextView&gt;

            &lt;LinearLayout android:orientation="horizontal"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:id="@+id/ID1"&gt;   
                &lt;EditText android:layout_marginLeft="5dip" 
                      android:id="@+id/keyword"
                      android:hint="e.g. Text here" 
                      android:textSize="17dip"
                      android:singleLine="true" 
                      android:layout_height="wrap_content" 
                      android:layout_width="250dip"/&gt;
                &lt;Button android:id="@+id/btnID"
                      android:textStyle="bold" 
                      android:layout_width="wrap_content" 
                      android:layout_height="wrap_content"
                      android:textColor="#FFFFFF"
                      android:background="@drawable/icon"
                      android:gravity="bottom"
                      android:paddingBottom="9dip"
                      android:layout_marginLeft="3dip"/&gt;      
            &lt;/LinearLayout&gt;

            &lt;LinearLayout android:orientation="horizontal"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:id="@+id/ID2"
             android:visibility="gone"&gt;   
                &lt;EditText android:layout_marginLeft="5dip" 
                      android:id="@+id/keyword"
                      android:hint="e.g. Text here"
                      android:textSize="17dip" 
                      android:singleLine="true" 
                      android:layout_height="wrap_content" 
                      android:layout_width="fill_parent"
                      android:layout_marginRight="5dip" /&gt;
            &lt;/LinearLayout&gt;      

&lt;Button android:text="Click" android:id="@+id/Button01" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt;&lt;/Button&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>Etext.Java</p>

<pre><code>public class EText extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ((LinearLayout)findViewById(R.id.ID1)).setVisibility(View.GONE);
    ((LinearLayout)findViewById(R.id.ID2)).setVisibility(View.VISIBLE);

    Button but = (Button) findViewById(R.id.Button01);
    but.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            String ETValue = ((EditText) findViewById(R.id.keyword)).getText().toString().trim();
            Toast.makeText(EText.this, ETValue, Toast.LENGTH_SHORT).show();
        }
    });
} }
</code></pre>

<blockquote>
  <p>Even this way doesn't works</p>
</blockquote>

<pre><code>public class EText extends Activity {
    /** Called when the activity is first created. */
    EditText ETextt1 = null;
    EditText ETextt2 = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        if(Integer.parseInt(Build.VERSION.SDK) &lt; 7){
            ((LinearLayout)findViewById(R.id.ID1)).setVisibility(View.GONE);
            ((LinearLayout)findViewById(R.id.ID2)).setVisibility(View.VISIBLE);
            ETextt1 = ((EditText) findViewById(R.id.keyword1));
        }else{
            ETextt2 = ((EditText) findViewById(R.id.keyword2));
        }

        Button but = (Button) findViewById(R.id.Button01);
        but.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                String ETValue = null;
                if(null == ETextt1){
                    ETValue = ETextt2.getText().toString().trim();
                }else if(null == ETextt2){
                    ETValue = ETextt1.getText().toString().trim();
                }

                Toast.makeText(EText.this, ETValue, Toast.LENGTH_SHORT).show();
            }
        });
    } }
</code></pre>

<blockquote>
  <p>This Works Perfectly Fine :-)</p>
</blockquote>

<pre><code>package com.test.et;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class EText extends Activity {
    /** Called when the activity is first created. */
    EditText ETextt1 = null;
    EditText ETextt2 = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        if(Integer.parseInt(Build.VERSION.SDK) &lt; 7){
            ((LinearLayout)findViewById(R.id.ID1)).setVisibility(View.GONE);
            ((LinearLayout)findViewById(R.id.ID2)).setVisibility(View.VISIBLE);
        }

        //ETextt = ((EditText) findViewById(R.id.keyword1));

        Button but = (Button) findViewById(R.id.Button01);
        but.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                String ETValue = null;
                if(Integer.parseInt(Build.VERSION.SDK) &lt; 7){
                    ETValue = ((EditText) findViewById(R.id.keyword2)).getText().toString().trim();
                }else{
                    ETValue = ((EditText) findViewById(R.id.keyword1)).getText().toString().trim();
                }

                Toast.makeText(EText.this, ETValue, Toast.LENGTH_SHORT).show();
            }
        });
    } }
</code></pre>
