我的应用程序有 Listview,Listview 项目有一个 TextView 和一个 Button 和其他图像等......我使用 ViewHolder 模式。
单击按钮时,我想更改 TextView 中的文本
如何在按钮 Onclick 中控制 TextView?
public class AListAdapter extends ArrayAdapter<MyData> {
static class ViewHolder {
TextView viewCountView;
ImageButton myButton;
ImageView profileImageView;
}
public View getView(int position, View convertView, ViewGroup parent) {
final AListAdapter adapter = this;
ViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.cell parent, false);
TextView viewCountView = (TextView) convertView.findViewById(R.id._view_count_);
Button likeButton = (ImageButton) convertView.findViewById(R.id._like_button);
LoadImageView profileImageView = (LoadImageView) convertView.findViewById(R.id.albumlist_profile_image);
holder = new ViewHolder();
holder.viewCountView = viewCountView;
holder.likeButton = likeButton;
holder.profileImageView = profileImageView;
holder.likeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// how to controll TextView??????????????????
// when click i want to change textview
//like holder.viewCountView.setText("clicked");
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
MyData data = (MyData) adapter.getItem(position);
if (data != null) {
holder.viewCountView.setText(String.valueOf(data.viewCount) + "views");
//image settings
}
return convertView;
}