我有一个带有自定义列表视图的应用程序,它有一个文本视图和一个图像视图。当我单击图像视图时,背景颜色应该会改变。我试图这样做,但得到NullPointerException
......这是我的代码
CustomListViewAdapter.java
public class ViewHolder {
TextView mName;
ImageView mDeleteImage;
}
public View getView(int position, View convertView, ViewGroup parent) {
holder = null;
DataFields rowItems = (DataFields) getItem(position);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.home_field_row, null);
holder = new ViewHolder();
holder.mName = (TextView) convertView.findViewById(R.id.hmFieldName);
holder.mDeleteImage = (ImageView)convertView.findViewById(R.id.hmFieldDeleteImage);
convertView.setTag(holder);
holder.mDeleteImage.setTag(position);
holder.mDeleteImage.setOnClickListener(new ImageView.OnClickListener() {
@Override
public void onClick(final View view) {
count++;
mListRowRL = (RelativeLayout)view.findViewById(R.id.hmFieldMainRL);
mListRowRL.setBackgroundColor(color.list_row_bg); //throwing NullPointerException
}
});
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.mName.setText(rowItems.getName());
return convertView;
}
任何形式的建议都非常感谢。谢谢 !