我有下一个 listView onItemClickListener - 工作正常。我在自定义适配器中放入 getView 的 onClick 方法。但是效果不好,只有当位置==0时才有效。为什么???
public class mySCAdapter extends SimpleCursorAdapter implements OnClickListener {
final String LOG_TAG = "myLogs";
LayoutInflater inflater;
public mySCAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
inflater = LayoutInflater.from( context );
// TODO Auto-generated constructor stub
}
@Override
public View getView( int position, View convertView, ViewGroup parent) {
View v = null;
if( convertView != null )
v = convertView;
else
v = inflater.inflate( R.layout.add_program_ex_list_item, parent, false);
ImageButton button = (ImageButton) v
.findViewById(R.id.add_program_exercise_list);
button.setTag(position);
button.setOnClickListener(this);
return super.getView(position, convertView, parent);
}
@Override
public void onClick(View v) {
Log.d(LOG_TAG, "It works, pos=" + v.getTag());
}
}