how to get the string from a listview item

by Kent Yip » Tue, 28 Apr 2009 11:15:10 GMT


Sponsored Links
 i have a method that fill the list with items

// Depending on param, this method will display the list
    public void fillData( RingtoneManager rm, int type ) {
        // Set all type of sounds; notification, ringtone, alarm
        rm.setType( type );
        c = rm.getCursor();

        startManagingCursor( c );

        String[] from = new String[] { RingtoneManager.EXTRA_RINGTONE_TITLE
};
        int[] to = new int[] { R.id.title };

        SimpleCursorAdapter rt =
            new SimpleCursorAdapter( this, R.layout.ringtones_row, c, from,
to );
        setListAdapter( rt );

    }// end fillData() method

when i select an item i want to be able to display the ringtone's title or
play the ringtone but i am having trouble doing so.

this get call when item is clicked

// Plays ringtone when cliking on the list item
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);

        // play the ringtone selected or get text/string from listview

        Toast.makeText( this, text, Toast.LENGTH_SHORT ).show();



    }// end onListItemClick() method

i tried this: l.getItemAtPosition( position )

that return an object data. but i have no clues as to what i could use to
extract string title from it.

I use toString() to get and idea what i am accessing and it's a
com.android.internal.sortcur...@12345678

please help, much appreciated.

--~--~---------~--~----~------------~-------~--~----~



how to get the string from a listview item

by Glen Humphrey » Tue, 28 Apr 2009 13:26:34 GMT


 Try something like this in your onListItemClick.

    TextView textView = (TextView) v.findViewById(R.id.title);
    String text = textView.getText().toString();



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


how to get the string from a listview item

by Glen Humphrey » Tue, 28 Apr 2009 13:47:57 GMT


 You could also do something like this in your onListItemClick.

    SQLiteCursor cursor = (SQLiteCursor) l.getItemAtPosition
(position);
    String title = cursor.getString(cursor.getColumnIndexOrThrow
(RingtoneManager.EXTRA_RINGTONE_TITLE));

On Apr 27, 10:26pm, Glen Humphrey <glendon.humphr...@gmail.com>



--~--~---------~--~----~------------~-------~--~----~



how to get the string from a listview item

by Glen Humphrey » Tue, 28 Apr 2009 14:37:49 GMT


 Try using Cursor instead of SQLiteCursor.






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Moving app to SD card

Hi,

as stated here: 
http://android-developers.blogspot.com/2010/07/apps-on-sd-card-details.html
, even if an app is installable on the SD card, the private data files
remain on the phone...

If this is true, my question is: are users aware of this? This would
mean that moving/installing on the SD card means only the app
installation is mobile, and not the database, for example. Do you know
more about actual use cases for this 'moving to SD card' feature?

I'm trying to figure this out because more and more users are asking
me to allow it to be movable to the SD, but i don't want to create
false expectations (e.g. user changes phone, keeps SD card, but loses
his 'stuff');

Thanks,
Teo

-- 

2. HTC Incredible & Android 2.2

Hey everyone,

                Anyone have any idea when 2.2 is going to be released for
the HTC incredible? Or is it better just to root my phone?

 

Thanks

                Mark

 

-- 

3. Dealing with password change on the server in a SyncAdapter

4. Android Virtual Key Touchscreen Driver Support

5. Checking the catagory of an installed application

6. Testing Microphone with Android App on OMAP

7. animation is starting with a large black screen....