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;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_act_two);
    tv = (TextView) this.findViewById(R.id.textView2);
}

public void report(View v) {
    if(v.getId() == R.id.button1)
        tv.setText(R.string.anrep);
    else
        tv.setText(R.string.iprep);
}

}

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