As you can see here I have a button called launchCreateNewRewardActivityBtn but it doesn’t work when I tap it. I have set up other buttons in the code and it seems to me like the code is the same for each of my other activities. So, to me, it seems like it should be working… Let me know if you need any more code or insight on this topic.
<?xml version="1.0" encoding="utf-8"?>
<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=".RewardsFrag"
android:padding="10dp"
android:background="@color/white">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create new reward"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/launchCreateNewRewardActivityBtn"
android:layout_marginBottom="50sp"
android:onClick="createNewReward"
/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rewardsRecView"
android:padding="10dp" />
</RelativeLayout>
Here is the on click listener … as you can see it is setup correctly; so I think atleast. However it doesn’t actually work unless I tab and then hit enter. What do I do?
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initializations
launchCreateNewRewardActivityBtn = view.findViewById(R.id.launchCreateNewRewardActivityBtn);
rewardsRecyclerView = view.findViewById(R.id.rewardsRecView);
dbHelper = new DataBaseHelperRewards(getContext());
// Initialize the adapter
adapter = new RewardsRecyclerViewAdapter(getContext(), dbHelper);
adapter.setRewards(rewards);
rewardsRecyclerView.setAdapter(adapter);
rewardsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
// Set the onClickListener on the button
launchCreateNewRewardActivityBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), CreateNewHabitActivity.class);
startActivityForResult(intent, requestCodeForCreateNewRewardActivityCall);
}
});
}