Android Programming Tutorials

(Romina) #1
Raising (Something Like) a Tweet

Figure 32. The initial Patchy layout, in landscape

Step #4: Listen for Send Actions........................................................


Next, we need to get control when the user clicks the Send button. This


involves finding the Send button in our layout and attaching a listener to it.


Replace the stock implementation of Patchy with the following:


package apt.tutorial.two;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Patchy extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button send=(Button)findViewById(R.id.send);

send.setOnClickListener(onSend);
}

private View.OnClickListener onSend=new View.OnClickListener() {
public void onClick(View v) {
}
};
}

158
Free download pdf