Assuming you use your own bean to store your website names and values ββand ArrayAdapter to show them in your ListView , e.g.
public class NamedLink { final String mName; final String mWebsite; public NamedLink(String name, String website) { mName = name; mWebsite = website; } @Override public String toString() { return mName; } }
With the adapter, define something like this:
mAdapter = new ArrayAdapter<NamedLink>(this, android.R.layout.simple_list_item_2, mLinks) { @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(WhateverYourActivityIsNamed.this).inflate(android.R.layout.simple_list_item_2, null); } NamedLink link = getItem(position);
When filtering the array adapter, it will match beans #toString() , which in this case returns the name. When filtering, the array adapter maintains a properly indexed copy of your beans list internally - that is, you can use the position that you get in the click listener as follows:
getListView().setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
source share