I am learning Android and trying one simple Android app development, I got one demo code from my lecture and the teacher simply do the following: There are 2 buttons, 1 textview. When touching button A, it will show "text A" in the textview, while touching button B, it will present "text B" in textview.

I followed the code and rewrote it, but i can't get the correct result when I ran with emulator.

When I touched either one button, there's no content in the textview. But teacher's reference code works. like this:

I paste the code here,

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

public class ActTwo extends Activity {

private TextView tv;

protected void onCreate(Bundle savedInstanceState) {
    tv = (TextView) this.findViewById(R.id.textView2);

public void report(View v) {
    if(v.getId() == R.id.button1)


How is report(View v) called? I can't understand how this class is called, could you please help me out? Thanks a lot!

Related posts

Recent Viewed