how to gettext from edittext in android?
<p>I use the following code to take values from the textbox.But it's not working it gives the exception and force to close only.How to get the value of the textbox ?can anyone help me? </p>

<pre><code>public class alertwithlogin extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    showDialog(1);
}
@Override
protected Dialog onCreateDialog(int id) {
  LayoutInflater factory = LayoutInflater.from(this); 
     final View textEntryView = factory.inflate(R.layout.alertedit, null); 
     return new AlertDialog.Builder(alertwithlogin.this)             
         .setTitle(R.string.alert_dialog_text_entry)
         .setView(textEntryView)
         .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int whichButton) {
              EditText edittext = (EditText) findViewById(R.id.username_edit); 
              Toast.makeText(getApplicationContext(),edittext.getText(),        Toast.LENGTH_SHORT).show();

             }
         })
         .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int whichButton) {                     
             }
         })
         .create();     
}
</code></pre>

<p>}</p>

<p>alertedit.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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"&gt;
&lt;TextView 
    android:id="@+id/username_view"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:text="@string/alert_dialog_username"
    android:gravity="left"
    android:textAppearance="?android:attr/textAppearanceMedium" /&gt;            
&lt;EditText
    android:id="@+id/username_edit"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
    android:scrollHorizontally="true"
    android:autoText="false"
    android:capitalize="none"
    android:gravity="fill_horizontal"
    android:textAppearance="?android:attr/textAppearanceMedium" /&gt;        
&lt;/LinearLayout&gt;
</code></pre>
