我目前正在将此代码用于按钮的侦听器来执行某些操作:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_row, null);
}
Person p = persons.get(position);
if (p != null) {
Button but = (Button) v.findViewById(R.id.buttonId);
but.setText(p.getDescription());
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do stuff
}
});
}
return v;
}
现在我想知道,这对内存管理有好处还是在活动本身中做一个 onListItemClick 更好?