Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Android sample . When buntton is clicked , it displays message with Toast.
<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"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<Button
android:id="@+id/button0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/toast"
android:layout_gravity="center">
</Button>
</RelativeLayout>
package com.example.andtoast;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
private Button button0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0=(Button)findViewById(R.id.button0);
button0.setOnClickListener(this);
}
public void onClick(View v){
Toast.makeText(this, "ボタンが押されました。", Toast.LENGTH_LONG).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AndToast</string>
<string name="hello_world">Hello world!</string>
<string name="toast">Toast!</string>
<string name="menu_settings">Settings</string>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment