How to display every other string within View getView()?
I've made a customAdapter that accepts an ArrayList. The ArrayList contains a title and then a link.
For example: [Title1, http://mylink1.com/, Title2, -http://mylink2.com/-, Title3, -http://mylink3.com/- ...] ** I've put hypens there because o开发者_如何转开发f the "Stackoverflow" Spam filter.
I'm wanting to display the title and then have the on click listener to have the link. I'm having trouble however figuring out a way to do this. Any help would be greatly appreciated! :)
The ArrayList needs to contain Link objects.
Ex.
class Link {
String title;
String url;
}
In getView of your Adapter you would use the title to fill the TextView, and in the onClick on onSelect or whatever, you would have the Link object with the title and url.
Ex.
public View getView(int index, View convertView, ViewGroup parent) {
TextView tv = (TextView) convertView;
Link link = list.get(index);
tv.setText(link.getTitle());
return tv;
}
public void onItemClick(ViewGroup parent, View view, int position, long id) {
Link link = list.get(position);
String uri = link.getUri();
// do something interesting.
}
And if your Adapter extends ArrayAdapter and you aren't overriding getView(), then the toString() method of Link needs to return the title field.
精彩评论