我在 onCreate() 状态下创建了一个 onClickListener。程序运行后,我处于 onResume() 状态,当我在 onResume() 状态下调用 onClickListener 时,它如何工作?
州之间不应该有区别:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button myButton= (Button) findViewById(R.id.button1);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView tv= (TextView) findViewById(R.id.textView1);
tv.setText("CIAO 1");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}