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. TCP/IP Communication between application running on development system with application running in Android emulator

Hello -

I would like to learn how to establish TCP/IP communication between an
application running on a development machine with an application
running inside the Android Emulator. When running the Android Emulator
I do not see an emulated network connection etc. I have read the
emulator documentation on the android developers page (http://
emulator.html#emulatornetworking) but am still not sure how to achieve
this goal. Any help would be much appreciated.

Matthew Roper


2. onActivityResult does not always get triggered when using IMAGE_CAPTURE with startActivityForResult

Hi all,

I am trying to track down and see if anyone else has encountered
something similar to a behavior i am seeing regarding the

Using the emulator it is the case that every time I call
startActivityForResult() and choose OK after taking a picture, the
code that I declared in my onActivityResult() function successfully
gets executed. However when I switch to a real device, ( I tested this
on both a Motorola droid and HTC Eris) there are cases that clicking
the OK or Done button within the camera app just results in the camera
app (IMAGE_CAPTURE intent) to simply restart instead of executing the
code in onActivityResult(). I also noticed that if I put a break point
in my onActivityResult() function when debugging with a device than
the break point gets hit every time. Additionaly this behavior seems
to be occuring more frequently in debug code (without the break point
in onActivityResult) than in release code.

It just seems like I am hitting a bizarre timing issue. I am wondering
if anyone out there has observed similar behavior in the IMAGE_CAPTURE
intent. I don't have any special intent-filters declared in my
androidmanifest.xml file for the activity i am using i wasn't sure if
i needed to specify anything in there.

Below is the code I am using to startup the IMAGE_CAPTURE intent and
the onActivityResult() function declared within the same class.

Any suggestions will be greatly appreciated.


public void onCreate(Bundle savedInstanceState) {
try {
                        Intent intent = new Intent(
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageURI);
                        startActivityForResult(intent, main.TAKE_PICTURE);
                } catch (Exception e) {

        protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
                Log.i("candup", "got the activity result");
                if (resultCode == Activity.RESULT_OK
                                && requestCode == main.TAKE_PICTURE) {
                        try {........}


3. Changing LandScape to Potrait mode

4. Can I create a sticky dialog?

5. How to alpha fade all Canvas drawing?

6. RadioGroup over two columns or rows?

7. Caller ID ON/OFF