要设置ListView的某些元素不可点击,我在自定义数组适配器中使用isEnabled方法,如下所示。奇怪的是,ListView本身的项目正确显示,但有些东西可点击。
可能有帮助的是,当我滚动时,突然Toast出现而不是在开头,给出的位置与不应该可点击的元素不对应并以黑色显示。 我有什么想法可以解决这个问题吗?
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder;
Object sRO = getItem(position);
title = sRO.getTitle();
description = sRO.getDescription();
isBuffered = sRO.getIsBuffered();
if (row == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.tvTitle = (TextView) row.findViewById(R.id.jText);
holder.tvDescription = (TextView) row
.findViewById(R.id.jDescription);
holder.checkbox = (CheckBox) row.findViewById(R.id.chk);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
if (isBuffered == true) {
holder.tvTitle.setText(title);
holder.tvDescription.setText(description);
holder.tvTitle.setTextColor(Color.BLACK);
holder.checkbox.setVisibility(View.VISIBLE);
} else if (isBuffered == false) {
holder.tvTitle.setText(title);
holder.tvTitle.setTextColor(Color.RED);
holder.tvDescription.setText(description
+ " - not supported");
holder.tvDescription.setTextColor(Color.RED);
holder.checkbox.setVisibility(View.GONE);
}
return row;
}
@Override
public boolean isEnabled(int position) {
if (isBuffered == false ) {
Toast.makeText(context, "false and "+position, Toast.LENGTH_SHORT).show();
return false;
} else {
Toast.makeText(context, "true and "+position, Toast.LENGTH_SHORT).show();
return true;
}
}