Simple question, but I am stuck 🙁 I was able to make this work when following the tutorial exactly, but when I tried to recreate it, my button would not work. There are no errors. It is just that nothing happens when I click the button. Any ideas?
public void listener() {
Button btnReset = (Button) findViewById(R.id.bl);
btnReset.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
resetCounter(v);
count = 0;
}
});
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Counter" >
<TextView
android:id="@+id/tvCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="@+id/bl"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/btnReset"
android:textSize="20sp" />
</RelativeLayout>
Thanks!
You have to call
listener()in yourOnCreate()method.