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)
    {
        super(v);
        
        // Inflate all your UI elements for the list entry ..
        
        // and ...
        v.setOnClickListener(this);
    }

    @Override
    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.

Apple publishes iphone-5 blueprints

For the first time Apple released the external blueprints of one of their devices to the public. Usually this is made available to accessory manufacturers. Now they’ve published it in their developer site.

Samsung can now start making its next phone. (I keeeed! I keeeed! 😀)

Source: developer.apple.com

Android Platform Version Share – September 2012

Google just published the monthly Android platform distribution. It shows that Android version 4.0 (ICS) has been growing at the same pace as last month, and version 4.1 (Jelly Bean) is just about getting a foothold in the market.

Version August September Change
# API
Jelly Bean 0.8% 1.2% +0.4%
v4.1 16
Ice Cream Sandwich 15.9% 20.9% +5.0%
v4.0 14 – 15
Honeycomb 2.3% 2.1% -0.2%
v3.x 12 – 13
Gingerbread 60.6% 57.5% -3.1%
v2.3 9 – 10
Frozen Yoghurt 15.5% 14.0% -1.5%
v2.2 8
Eclair 4.2% 3.7% -0.5%
v2.1 7
Donut 0.5% 0.4% -0.1%
v1.6 4
Cupcake 0.2% 0.2% 0%
v1.5 3

ICS usage share got a bit of a boost from the upgrades as well as some of the new phones. In next months statistics, we should see some of this boost shift to Jelly Bean if the most popular phone right now e.g. the Samsung Galaxy S3 gets upgraded. Along with other phones due for release this may put Jelly Bean at nearly 10%. or at least I hope! Otherwise the Jelly Bean share should hover around 2% while the ICS share rises to the mid-20%.

We’re unlikely to see the Gingerbread usage share decrease any quicker then the current rate as the phones still on this version are bound to stay on it. This will just get diluted as new phones come to market, and old phones are discarded.

List of phones that come with the Carrier IQ spyware

Carrier IQ is a spyware program for mobile phones that has been in the news a fair amount in recent weeks. It is able to record many things including the list of installed apps, the location of the device, buttons pressed including keystrokes on the soft keyboard, and the content of messages. This data is sent to the Carrier IQ servers and then onto the mobile service provider which can be used for generating statistics or further relayed onto third parties such as advertisers, and law enforcement. This program cannot be uninstalled without rooting the phone.

While service providers and Carrier IQ claim that they do not store the content of messages, it has been found that they are infact doing this. They claim that this is a bug, and they are working on a fix.

Currently in the US, AT&T and T-Mobile include this program in their phones, while Verizon has made clear that they do not use it.

From an alleged T-Mobile document it appars that the following phones contain Carrier IQ:

  • HTC Amaze 4G
  • Samsung Galaxy S II
  • Samsung Exhibit II 4G
  • T-Mobile myTouch by LG
  • T-Mobile myTouch Q by LG
  • LG DoublePlay
  • BlackBerry 9900
  • BlackBerry 9360
  • BlackBerry 9810

So, I’d steer clear of any of those phones on AT&T or T-Mobile if I were you. (In fact I’d steer clear of those networks alltogether! :p)

Mobile operators in the UK do not use Carrier IQ.

via: The Verge

Flash and the mobiles

The smartphone market is finally getting a full-fledged flash player. Adobe’s CTO Kevin Lynch demonstrated Flash 10 running on Nokia Series 60 (based on Symbian), Windows Mobile and even the Google Android platforms. There was a major but expected absentee … The iPhone.

The smartphone market is finally getting a full-fledged flash player. Adobe CTO Kevin Lynch demonstrated Flash 10 running on Nokia Series 60 (based on Symbian), Windows Mobile and even the Google Android platforms. There was a major but expected absentee … The iPhone.

While Adobe has a near complete version for the iPhone, it’ll probably never be released to the wild. The problem as some see it is that it is too close for comfort for Apple, providing a free application platform that would compete with the App Store. They would lose the tight control they have on what can be run on an iPhone, as well as losing the revenue stream from sales via the App Store.
Continue reading “Flash and the mobiles”

Minimo is no more …

Minimo – Mozilla’s mobile browser project has been cancelled.

Minimo Logo
It appears that Minimo – Mozilla’s mobile browser project has been scrapped. Despite of being slimmed down, it was still quite slow on windows mobile. I guess that’s the reason for it meeting its demise.

Pity, it seemed like a better browser than the stock browser supplied on many devices like Opera mini in the Nokia n800. It’s full featured Gecko renderer with the Javascript engine allowed Ajax heavy sites such as Google Docs to work just fine on the device, which was not possible with Opera mini.