|
Different type of onClick listener |
1st method:
1. The Xml Android: Onclick = "name" to be selected.
II. Now that the methada to build Java. As public void name (View v) {}
2nd method:
1. Button to Decleare. As Button newButton;
II. Xml button to connect at will. For example btnTest = (Button) findViewById (R.id.btnTest);
3. Then call. For example:
btnTest.setOnClickListener (new OnClickListener () {
@Override
public void onClick (View v) {
Log.e ( "Hi", "hi");
}
});
3rd method:
public class MainActivity extends Activity implements OnClickListener {
Button btnTest;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
btnTest = (Button) findViewById (R.id.btnTest);
btnTest.setOnClickListener (this);
}
@Override
public void onClick (View v) {
(Declare the action buttons.)
}
}