Skip to content

Instantly share code, notes, and snippets.

@agneym
Created January 29, 2016 07:33
Show Gist options
  • Save agneym/e02d27c46965892290e4 to your computer and use it in GitHub Desktop.
Save agneym/e02d27c46965892290e4 to your computer and use it in GitHub Desktop.
Just another Button and Edit Text
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:layout_gravity="center"
tools:context="agney.alpha.com.helloworld.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Search Term"
android:id="@+id/editText"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_gravity="center_horizontal"
android:text="Search"/>
</LinearLayout>
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent (MainActivity.this ,DisplayActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE,message);
startActivity(intent);
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment