java ImageView背景在行中
我想在列表行中设置一个图像资源的背景图像,但是下面的代码对背景没有影响,它根本不影响背景
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView mobileNo=(TextView)view.findViewById(R.id.text1);
mobileNo.setText(cursor.getString(cursor.getColumnIndex(NotesDbAdapter.KEY_TITLE)));
TextView frequency=(TextView)view.findViewById(R.id.date);
frequency.setText(cursor.getString(cursor.getColumnIndex(NotesDbAdapter.KEY_COLOR)));
String color = (cursor.getString(cursor.getColumnIndex(NotesDbAdapter.KEY_COLOR)));
ImageView background=(ImageView)view.findViewById(R.id.album_image);
if (color == "#57a2f6"){
background.setImageResource(R.drawable.bluebg);
}
else if (color == "#00cdb1"){
background.setImageResource(R.drawable.redbg);
}
# 1 楼答案
您正在尝试将}
String color
与==
进行比较,这是not valid in java
如此 使用eaquals()
{所以你的代码应该是