android listView 中存在editView chetxBox等点击事件处理
2010-05-24 16:32:00 来源:WEB开发网// createHolder will be called only as long, as the ListView is not filled
// entirely. That is, where we gain our performance:
// We use the relatively costly findViewById() methods and
// bind the view’s reference to the holder objects.
TextView text = (TextView) v.findViewById(R.id.listitem_text);
ImageView icon = (ImageView) v.findViewById(R.id.listitem_icon);
ViewHolder mvh = new MyViewHolder(text, icon);
// Additionally, we make some icons clickable
// Mind, that item becomes clickable, when adding a click listener (see API)
// so, it is not necessary to use the android:clickable attribute in XML
icon.setOnClickListener(new ClickableListAdapter.OnClickListener(mvh) {
public void onClick(View v, ViewHolder viewHolder) {
// we toggle the enabled state and also switch the icon
MyViewHolder mvh = (MyViewHolder) viewHolder;
MyData mo = (MyData) mvh.data;
mo.enable = !mo.enable; // toggle
ImageView icon = (ImageView) v;
icon.setImageBitmap(
mo.enable ? ClickableListItemActivity.this.mIconEnabled
: ClickableListItemActivity.this.mIconDisabled);
}
});
// for text we implement a long click listener
text.setOnLongClickListener(new ClickableListAdapter.OnLongClickListener(mvh) {
@Override
public void onLongClick(View v, ViewHolder viewHolder) {
MyViewHolder mvh = (MyViewHolder) viewHolder;
MyData mo = (MyData)mvh.data;
// we toggle an ‘*’ in our text element
String s = mo.text;
if (s.charAt(0) == ‘*’) {
mo.text = s.substring(1);
} else {
mo.text = ‘*’ + s;
}
mvh.text.setText(mo.text);
}
});
return mvh; // finally, we return our new holder
更多精彩
赞助商链接