Having trouble getting ListView to show selected item as highlighted

by Timothy DeWees » Sat, 27 Dec 2008 07:08:09 GMT

Sponsored Links

I've seen a few post on this but have never seen or understood the
solution.  I have an application that is showing a list of items from
a database.  I extended the CursorAdapter and added an icon in front
of the item to easily show type.

When I navigate the items using the track-pad, it shows the selected
item; however, when I click the item, the selection goes away.  It's
still there and when I use the track-pad again, it seems to be getting
the focus back and then I can scroll.

What I want to happen is for the list item to appear highlighted when
I click it just like when I navigate to it with the trackpad.

Any suggestions?

Here are my onClick and onItemSelected:

    protected void onListItemClick(ListView l, View v, int position,
long id) {
        super.onListItemClick(l, v, position, id);
        movieId = id;
    public void onCreate(Bundle savedInstanceState) {

        mDbHelper = new MoviesDbAdapter(this);
        Button filterButton = (Button)findViewById
        filterButton.setOnClickListener( new View.OnClickListener() {
                public void onClick(View v){
                        EditText filter = 
                        filterExpr = filter.getText().toString();
        getListView().setOnItemSelectedListener( new
OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> parent, View v, int
possition, long id) {
                        movieId = id;
                public void onNothingSelected(AdapterView<?> parent) {


Other Threads

1. problem with Hello, Gallery R.styleable not resolve

Thanks for catching the typo!  I should have just done a copy/paste... :)
Glad I could help somewhat.

There are only 10 types of people in the world...
Those who know binary and those who don't.

On Mon, Aug 31, 2009 at 9:39 PM, Bui Quang Hao(Johny.Bui) <


2. Create New TextView Style....

I want to create a new style that slightly modifies the default style
of a TextView...  However, I have not been able to find what the value
for the parent attribute should be...

Any help would be appreciated!

Current xml code:

<?xml version="1.0" encoding="utf-8"?>
        <style name="TitleText" parent="??????????">
                <item name="android:textSize">25sp</item>
                <item name="android:textColor">#008</item>

3. Showing directions or drawing required path on Google Maps

4. setPadding() in onDraw() causing ListView draw loop

5. Problem in Geoceder Address and Country name are not Displaying

6. Services - best way to bind

7. TextView Line Breaks