我已经制作了自定义列表视图,其中我还添加了一个textview。我想要花费所有被省略的文本,因此我也在textView上设置了onClickListener,但是当我点击textView时它什么也没做,只是在第二次单击它执行我的功能。这是我的代码
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final CruunNotificationModel cruun = userDetails.get(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.imagewithlist, null);
holder = new ViewHolder();
holder.userComments = (TextView) convertView
.findViewById(R.id.userCommentsTextView);
holder.userName = (TextView) convertView
.findViewById(R.id.userNameTextView);
holder.dateTime = (TextView) convertView
.findViewById(R.id.dateTimeTextView);
holder.userImage = (ImageView) convertView
.findViewById(R.id.userImageImageView);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.userComments.setText(cruun.getComments());
holder.userName.setText(cruun.getUserName());
holder.dateTime.setText(cruun.getDataAndTime());
holder.userImage.setImageResource(cruun.getImageId());
holder.userComments.setFocusable(false);
holder.userComments.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.userComments.setEllipsize(null);
RelativeLayout.LayoutParams lParams = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lParams.addRule(RelativeLayout.RIGHT_OF, R.id.userImageLayout);
holder.userComments.setLayoutParams(lParams);
notifyDataSetChanged();
}
});
return convertView;
}
static class ViewHolder {
TextView userComments;
TextView userName;
TextView dateTime;
ImageView userImage;
}
答案 0 :(得分:0)
从holder.userComments.setFocusable(false);
中删除此行getView
,然后检查。
答案 1 :(得分:0)
我建议你将你的TextView转换成xml&中的Button。将其背景设置为透明!
这将被视为TextView&你可以执行你的代码更新