TimeParadox
TimeParadox

Reputation: 139

add onClick listener on Android ListView With SimpleAdapter

I didn't found the solution with the search :(

I'm programming an application for reading RSS feeds.
I'm using a listview for putting a screen title and description of every feed into 2 textview. I realized that with a SimpleAdapter.

In my project I have 2 classes: MainActivity and AsynkTask. In mainActivity I execute the asyncTask that reads RSS and puts them into the adapter and the listview

Now, how can I add a click listener on the listview for opening every feed into the browser?

I hope that I've explained correctly the problem and I'm sorry for my very bad english! Thanks to all.

PS: if you need some of my code i will post it.

Upvotes: 1

Views: 12635

Answers (2)

Chris
Chris

Reputation: 3017

In the onCreate method of your MainActivity, if it's a ListActivity, you need to get a reference to your list view like so:

ListView lv = getListView();

Then add a click listener to it like so:

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) { 
  //Open the browser here
}

Upvotes: 7

nwaltham
nwaltham

Reputation: 2084

On your list view, you need to use setOnItemClickListener

Upvotes: 1

Related Questions