onListItemClick with Mulitple Value/Retrieving Value
Posted
by JuniorFlip
on Stack Overflow
See other posts from Stack Overflow
or by JuniorFlip
Published on 2010-05-22T20:45:07Z
Indexed on
2010/05/22
20:50 UTC
Read the original article
Hit count: 321
Hello, I am trying to retrieve the value from a Arraylist/ArrayAdapter that I have populated. I believe my issue is at the Onitemclick event. What I would like to accomplished is that when I click on Yasmin, I can return the value of 8. Please let me know if I am on the right track
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener;
public class lister extends Activity { /** Called when the activity is first created. */ TextView txHomeTeam; protected ListView mFavlist; protected ArrayList fakeFavs = new ArrayList();
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); this.setContentView(R.layout.main);
this.txHomeTeam = (TextView)this.findViewById(R.id.title);
fakeFavs.add(new Favorite("John", "1"));
fakeFavs.add(new Favorite("Yasmin", "8"));
fakeFavs.add(new Favorite("Jack", "10"));
//this.mFavlist = (ListView) this.findViewById(R.id.list_favorites);
this.mFavlist = (ListView) this.findViewById(R.id.list_favorites);
initListView();
mFavlist.setTextFilterEnabled(true);
mFavlist.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView arg0, View view,
int position, long id) {
// user clicked a list item,
//and read the value from <Favorite>.value
//txHomeTeam.setText=????
}
});
}
public void refreshFavListItems() { mFavlist.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, fakeFavs)); }
public void initListView() {
/* Loads the items to the ListView. */
refreshFavListItems();
}
protected class Favorite { protected String Detail; protected String value;
protected Favorite(String Detail, String value) {
this.Detail = Detail;
this.value = value;
}
public String toString() {
return Detail;
}
}
}
© Stack Overflow or respective owner