how to implement a long click listener on a listview

You have to set setOnItemLongClickListener() in the ListView: lv.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) { // TODO Auto-generated method stub Log.v(“long clicked”,”pos: ” + pos); return true; } }); The XML for each item in the list (should you use a custom XML) must have android:longClickable=”true” as … Read more

How do I create a ListView with rounded corners in Android?

Here is one way of doing it (Thanks to Android Documentation though!): Add the following into a file (say customshape.xml) and then place it in (res/drawable/customshape.xml) <?xml version=”1.0″ encoding=”UTF-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”rectangle”> <gradient android:startColor=”#SomeGradientBeginColor” android:endColor=”#SomeGradientEndColor” android:angle=”270″/> <corners android:bottomRightRadius=”7dp” android:bottomLeftRadius=”7dp” android:topLeftRadius=”7dp” android:topRightRadius=”7dp”/> </shape> Once you are done with creating this file, just set the background in … Read more

Android ListView Selector Color

The list selector drawable is a StateListDrawable — it contains reference to multiple drawables for each state the list can be, like selected, focused, pressed, disabled… While you can retrieve the drawable using getSelector(), I don’t believe you can retrieve a specific Drawable from a StateListDrawable, nor does it seem possible to programmatically retrieve the … Read more