1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
package com.example.planar;
import java.io.*;
import android.app.Activity;
import android.os.Bundle;
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 buttonWithActivityAsListener;
private Button buttonWithInnerClassAsListener;
private Button buttonWithInlineAsListener;
private final ClientSocket clientSocket = new ClientSocket();
private String imageName ="image_delete -1 gui\n\n";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonWithActivityAsListener = (Button) findViewById(R.id.button_with_activity_as_listener);
buttonWithActivityAsListener.setOnClickListener(this);
buttonWithInnerClassAsListener = (Button) findViewById(R.id.button_with_inner_class_as_listener);
buttonWithInnerClassAsListener.setOnClickListener(new InnerOnClickButtonListener());
buttonWithInlineAsListener = (Button) findViewById(R.id.button_with_inline_class_as_listener);
buttonWithInlineAsListener.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button with Inline Class as Listener has been clicked.", Toast.LENGTH_SHORT).show();
}
});
}
/** You implement this method after adding OnClickListener interface to your Activity. **/
public void onClick(View v) {
Toast.makeText(this, "Button with Activity as Listener has been clicked.", Toast.LENGTH_SHORT).show();
}
//
/** Name of the method and it's triggering comes from main.xml file.
* Button's widget attribute android:onClick allows you to specify name of the method
* which you have to implement.
* @throws IOException **/
public void onButtonClick(View v) throws IOException {
Toast.makeText(this, "efface le mur.", Toast.LENGTH_SHORT).show();
String texte =clientSocket.call(imageName);
Toast.makeText(this, texte, Toast.LENGTH_SHORT).show();
}
/** Inner Class to respond to OnClick events. **/
class InnerOnClickButtonListener implements OnClickListener {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Button with Inner Class as Listener has been clicked.", Toast.LENGTH_SHORT).show();
}
}
} |