addEventListener vs onclick

What’s the difference between addEventListener and onclick? var h = document.getElementById(“a”); h.onclick = dothing1; h.addEventListener(“click”, dothing2); The code above resides together in a separate .js file, and they both work perfectly. 2Best Answer 21 Both are correct, but none of them are “best” per se, and there may be a reason the developer chose to … Read more

RecyclerView onClick

As the API’s have radically changed, It wouldn’t surprise me if you were to create an OnClickListener for each item. It isn’t that much of a hassle though. In your implementation of RecyclerView.Adapter<MyViewHolder>, you should have: private final OnClickListener mOnClickListener = new MyOnClickListener(); @Override public MyViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) { View view … Read more