开发学院手机开发Android 开发 android listView 中存在editView chetxBox等点击... 阅读

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 fi

// 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

上一页  1 2 3 4 5 6 7  下一页

Tags:android listView 存在

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接