Reputation: 87
I'm trying to learn android development with Android Studio but I can't seem to figure out why my clicks are not registering. Is there something I'm missing here?
I don't like the way Stack Overflow FORCES me to format things they way THEY want. Here is pastebin! :_
Upvotes: 0
Views: 16408
Reputation: 6515
call this changeText()
method inside onCreate()
method of your activity
your activity should look like this:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
changeText();
}
public void changeText(){
final Button button = (Button) findViewById(R.id.button1);
final TextView text = (TextView)findViewById(R.id.largetext);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
button.setText("Button has been pressed");
text.setText("The large text has been changed");
}
});
}
}
Upvotes: 5
Reputation: 2320
In fact, you didn't set the listener. So you should add changeText()
after setContentView(R.layout.activity_my);
.
Upvotes: 4