Reputation: 21
I have an activity which onCreate starts a listener for a button onclick, as below:
buttonCal = (Button) findViewById(R.id.buttonCal);
buttonCal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
calAge();
}
});
The code then do puts some text into a textview.
TextView txtAGE = (TextView) findViewById(R.id.txtAGE);
txttxtAGE.setText(strAGE);
The code work fine, once. I have tried putting the listener code below the setText() function and it still doesn't work. Does anybody know why? or how I can get it so the button can be pressed an infinite amount of time and calculate a new age and display it in textview?
thanks for any help :)
Upvotes: 0
Views: 1530
Reputation: 75788
It would be helpful to know what code you are trying to execute when the button is pressed. You've got the onClick property set in your xml file to a method called Button_Click.
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="Button_Click"
android:clickable="true"/>
Now in your Java Class
public void Button_Click(View i)
{
//do your code
}
Upvotes: 1