Month: September 2016

Adding Keyboard Navigation to a RecyclerView

List showing selected tab only

I’ve created a list of items using a RecyclerView which works fine (see the screenshot). But, in order to keep my app accessible, I need to support keyboard-based navigation. Just using the normal Recyclerview pattern and the associated layout was not good enough. If I use a keyboard, I am unable to move the focus down into the list, the focus stops in the tab control and then cycles back up to the app bar. Tapping the items with your finger works fine, and even switch access moves the focus properly to the list items. But it doesn’t work for the keyboard.

The trick is to set the LinearLayout to focusable and clickable, and set the background of the LinearLayout to:

android:background="?android:attr/selectableItemBackground"

as shown below in the XML layout snippet below. These three changes allow the list items to be selectable by the keyboard.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground"
    android:focusable="true"
    android:clickable="true"
    android:paddingBottom="5dp">

    <ImageView
        android:id="@+id/item_image"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginTop="8dp"
        android:adjustViewBounds="true"
        android:layout_weight="1"/>
    <TextView
        android:id="@+id/item_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:paddingTop="12dp"
        android:layout_weight="8"/>

</LinearLayout>

What should I build?

Crystal Clear app ktip

I’ve been asked by developers who are learning this exact question. They want to build something to practice their skills or learn a new language or platform, but they don’t have ideas. Luckily, there are solutions for this problem that don’t require the next great idea.

Recreate A Simple App

Look in the App Store or Google Play for a really simple app. A timer, flashcards, a calculator, a pedometer. It doesn’t matter. Make one of your own, use the one you found as a set of requirements. You don’t need to publish the app, you just need to have something to build. If you can publish it, that’s even better but the goal is to practice and get better at coding.

I did a variation this one. Initially, I made a flash card game for my daughter to learn her fact families. The school required here to complete 50 problems in under 2 minutes. I couldn’t find any game at the time that had that feature, so I made one myself. Since that time I’ve re-written that game on two additional platforms (Silverlight and Android) and even ended up publishing it.

Hackathons

Hackathons are events where a bunch of programmers get together and build things. Sometimes it’s for fun, sometimes it’s to help others, like nonprofit organizations or the local government.The ideas typically come from organizations who need help. Sometimes hackathons¬†are competitive and have prizes. They can be in person or online. Usually they take place over time time period, from hours to weeks in duration. You can find a list of hackathons at DevPost. In-person hackathons are great because you can learn from other developers and network with your peers. The online versions are more likely to offer prizes though.

Open Source

You can contribute to an open source project. It’s helpful if it’s a project you are already familiar with. Look at their issues list. There are bound to be bugs reported that need fixing. Fork the code, fix the bug, submit a pull request. Make sure you talk to the project leaders though and understand what they are looking for in pull requests so you head down the right path when you start fixing the bug. This route helps you learn to read code, and get good experience setting up a development environment for someone else’s work.

Exercises for Programmers

This book from the Pragmatic Programmer series provides a set of exercises you can use to build something. Lots of them are small, but there are quite a few that could be a full app. Not original ideas you could probably publish, but still plenty of ideas you could build.

Learning To Have Ideas

Like any other skill, having ideas can be learned and practiced. In the end it’s a numbers game, you need to have lots of bad ideas in order for some good ones to come out. Set aside time and try to come up with ideas, no matter the quality. Write them down. Do it again tomorrow, and again after that. Before long you will start to see better ideas emerging. But you need to keep at it. Doing it once isn’t going to work.