-1
我有一個裝滿物品的ListView
。我想設置一個onClickListener
以顯示有關點擊項目的詳細信息。我如何確定在onClickListener
內點擊了哪個項目? View
或v
有很多可用的方法,但我沒有看到任何與點擊對象有關的方法。如何知道哪個列表項被點擊?
//populate the activity list
ListView teamsListView = (ListView) activity.findViewById(R.id.teamsListView);
ArrayList<HashMap<String, String>> listData = new ArrayList<HashMap<String, String>>();
HashMap<String, String> listItem;
for (TeamSet teamSet : response.getTeamSetList()) {
listItem = new HashMap<String, String>();
listItem.put("name", teamSet.getName());
//listItem.put("teamCount", Integer.toString(teamSet.getTeams().size()));
listData.add(listItem);
}
teamsListView.setAdapter(
new SimpleAdapter(
context,
listData,
R.layout.teams_list_row,
new String[]{"name"},
new int[]{R.id.teamsTeamListName}
)
);
//show details on a team
TextView team = (TextView) activity.findViewById(R.id.teamsTeamListName);
team.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//how do I know which item was clicked? I want to load more details on the item...
}
});
[OnItemClickListener](http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html)? – keyser
我喜歡我如何得到2票反對提出問題...在這個網站上的一些人...... – Webnet
我認爲這是因爲你沒有顯示任何研究工作 – keyser