嗨,我有一个问题。想知道如何从OnItemClick方法中获取某些值。我可以得到位置,但看到我在这个位置有超过1个textview是否有可能获得第一个textview?
继承我的代码
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
for(int i=0; i<poi.length; i++){
map = new HashMap<String, String>();
map.put("first", poi[i][0]);
map.put("second",poi[i][1]);
mylist.add(map);
}
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.row,
new String[] {"first", "second"}, new int[] {R.id.FIRST, R.id.SECOND});
list.setAdapter(mSchedule);
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Log.i("owen", Integer.toString(position));
//my code to get "first" string on click
}
由于
答案 0 :(得分:1)
如果您知道所需textview的资源标识符,则可以将传递给onitemClick()方法的视图找到该子项:
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
TextView myText = (TextView) v.findViewById(R.id.my_textview);
Log.i("owen", myText.getText().toString());
}
该位置与AdapterView列表中的行位置有关。