覆盖对象的toString会使ListView行无法点击?

时间:2013-04-20 21:50:09

标签: java android

我遇到了一个奇怪的问题。我有一个简单的ListView与onItemClickListener。当我覆盖列表对象的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();
    }
}

怎么回事?

0 个答案:

没有答案