Skip to content

Instantly share code, notes, and snippets.

@tomorrowkey
Last active August 29, 2015 14:18
Show Gist options
  • Save tomorrowkey/663bca5a90be8a9aabbb to your computer and use it in GitHub Desktop.
Save tomorrowkey/663bca5a90be8a9aabbb to your computer and use it in GitHub Desktop.
<RelativeLayout
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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<Button
android:id="@+id/click_me_button"
android:text="Click me!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.click_me_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Hello!", Toast.LENGTH_SHORT).show();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment