package com.registerevent;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Button b1, b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(bListener);
b2.setOnClickListener(bListener);
}
private OnClickListener bListener = new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String label = ((Button)v).getText().toString();
Toast.makeText(getBaseContext(), "you click" +label, Toast.LENGTH_LONG).show();
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Home
› android application development tutorial
› android development tutorial
› android programming video tutorial
› android tutorial video
› android video tutorial
› android views
› Registering events for views
Subscribe to:
Post Comments (Atom)