我有一个奇怪的问题。我有一个带有 onItemClickListener 的简单 ListView。当我覆盖列表对象的 toString 时,它会正确显示,但点击停止工作。当我在 toString 中调用 super 时,点击工作正常。
来自 onCreate:
ListView listView = (ListView) findViewById(R.id.listview);
SearchAdapter searchAdapter = new SearchAdapter(this, 0, 0, CalendarActivity.satellites);
listView.setAdapter(new ArrayAdapter<Satellite>(this, R.layout.search_cell, R.id.name, CalendarActivity.satellites));
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
startActivity(new Intent(SearchActivity.this, DayActivity.class));
}
});
卫星:
public class Satellite {
public String url;
public boolean active;
public String name;
public int id;
public ArrayList<Date> dates;
@Override
public String toString() {
if (!name.isEmpty()) { //note that this still fails the onClick
return name;
} else {
return super.toString();
}
}
这是怎么回事?