what I have now is a listView with 3 items in it: Audience, Choosing topics, and Interviewing strategies. I want to be able to save these items as strings to open url with associated item name in the path, but the problem comes when the path has a different item name than the one I have in the listview items; we have Audience, Choosing_topics, and Interviewing as their names. How would I go about dealing away with this conflict in name without changing the names of the url or the listViewItem? Should I refer to another string array to compare the value of the first string array to to retrieve the associated item in the new array? Here’s what I have as of now:
setListAdapter(new ArrayAdapter(this, R.layout.list_item, GREATESTHITS));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String text = (String) ((TextView)view).getText();
((GlobalVariables)getApplication()).setGlobalVariable(text);
String str = DownloadText("http://www.jmu.edu/uwc/" + text + ".html");
static final String[] GREATESTHITS = new String[] {"Audience", "Choosing topics", "Interviewing Strategies"};
I’d say the best way to deal with this is to use objects. You create a model for each of your strings on your
GREATESTHITS. You can then add another property for the url or whatever extra you want.After that is created, you create and
ArrayAdapter<YourTypeHere>and on theListViewyou can set the adapter you just created.After that on the
ItemClickListeneryou can use this:there you have the object on the array, and you can access all the properties you’ve set for that object.
This seems a little bit overkill for only 3 items, but it is the right way to go.
On an easier approach you can set a
HashMap<String, String> urlNames, add a hash with each text and it’s relative url. After that, on the listener you can do