J
JinDroid
Guest
hello all
i am trying to create a project to enter some text into a edittext widget and then when a a button is pressed to show the content of the edittext field to a toast message.
i have gone throught the tutorials on the android developer resources website and i belive i have almost got it but as eclipse is not showing any errror's with my code i dont understand how to correct the problem.
Could anyone point me in the right direction ?
my main.xml file is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android: orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android: padding="10dp"
android:background="@drawable/android_button" />
<EditText
android:id="@+id/field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
and here is the .java class file.
package com.example.TextApp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class TextApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final EditText fld = (EditText) findViewById(R.id.field);
final Button button = (Button) findViewById(R.id.field);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(TextApp.this, fld.getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
i am trying to create a project to enter some text into a edittext widget and then when a a button is pressed to show the content of the edittext field to a toast message.
i have gone throught the tutorials on the android developer resources website and i belive i have almost got it but as eclipse is not showing any errror's with my code i dont understand how to correct the problem.
Could anyone point me in the right direction ?
my main.xml file is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android: orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android: padding="10dp"
android:background="@drawable/android_button" />
<EditText
android:id="@+id/field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
and here is the .java class file.
package com.example.TextApp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class TextApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final EditText fld = (EditText) findViewById(R.id.field);
final Button button = (Button) findViewById(R.id.field);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(TextApp.this, fld.getText(), Toast.LENGTH_SHORT).show();
}
});
}
}