Adding click handler for RecyclerView List Entries

If you’re migrating from the ListView to RecyclerView in API Level 21 support library (i.e. Android 5.0 / Lollipop), you may be wondering how to add a click listener for entries in the list. With the ListView you would provide a single listener for all list entries using the ListView.setOnItemClickListener() method, which takes an implementation of the AdapterView.OnItemClickListener interface as its parameter. In your implementation of this interface you would override the onItemClick() method where you are given the ListView instance, the View for the entry in the list, its position, and ID as method parameters.

The stumbling block with the RecyclerView is that it does not have this setOnItemClickListener() method. The solution is actually quite simple, you can use the standard setOnClickListener() method provided by the View object. You can do this for the View objects corresponding to each list entry.

You would typically inflate the required View object from the respective resource definition in your override of the RecyclerView.Adapter.onCreateViewHolder() method. You would also construct your version of the RecyclerView.ViewHolder class there and pass the inflated View object as a constructor parameter.

The View.setOnClickListener() accepts a View.OnClickListener implementation as its parameter, and your ViewHolder is a good place to implement this. This is because the ViewHolder class has access to the list entry View object, its parent, position, and ID which are exactly the same as the parameters you were provided in the old ListView onItemClick() method.

Your ViewHolder class could look something like the following:

public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
    protected ViewHolder(View v)
        // Inflate all your UI elements for the list entry ..
        // and ...

    public void onClick(View v)
        int pos = this.getPosition();
        long id = this.getItemId();
        ViewParent parent = v.getParent();

And that’s really it! The code above should provide a good start for your ViewHolder class. Hopefully this has been helpful.

Window Manager missing after Upgrading Ubuntu

When I upgraded Ubuntu from 14.04 (Trusty Tahr) to 14.10 (Utopic Unicorn), the computer booted up fine after the restart. But after logging in, the Window Manager didn’t start up!

TL;DR … To fix this, delete the ~/.config/dconf/user file (or rename it), and then restart the computer.

When I logged in, the desktop was there with all the icons on it, but the top menu bar, and the side-bar were missing. When I opened up a window by clicking on a folder icon in the desktop, it would open, but it would be missing the title bar. So, basically seemed like the Window Manager was missing. After deleting the above mentioned file and restarting, it was all good again!

Require all granted

Just upgraded my web server to the current version of ubuntu and got caught out by a change in apache httpd. (Note to self: RTF-release-notes next time.)

It resulted with a 403 / Forbidden error, with the browser showing You don’t have permission to access / on this server, and a client denied by server configuration entry in the log.

The issue was the addition of mod_authz. It needs a new entry in the Directory section of your web site config:

Require all granted

It is equivalent to the old allow from all. Check the Apache mod_authz_core page for more details.

Luckyily this time it was a fairly easy fix, and mod_authz seems to have some fairly interesting features to explore. In any case, if your web sites stop working after an upgrade in your ubuntu server, this is probably the issue.

Oh Noes!!!! Thwarted by @font-face support in Google Chrome on Windows

Gotta love web development! It’s 2014, and yet @font-face/webfont support still sucks. The woff fonts look fantastic in Firefox, Chrome, and Safari on a retina macbook. Pretty OK in Firefox in Windows 7 on a 1080p monitor. But in Chrome on the same system, the thin fonts (i.e. fonts with weight 100) seem to have bits missing. Even on Google’s own roboto font! Ah well!

Oh yeah, I am also aware of a web browsing application called Internet Explorer. :)