2013-08-02 67 views
1

我想在列表行中設置圖像資源的背景圖像,下面的代碼如何對背景沒有影響,它根本不影響背景。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); 
      } 

回答

0

您要比較String color==這是not valid in java所以 使用​​for comparison of Strings

所以你的代碼應該是

if (color.equals("#57a2f6")){ 
    background.setImageResource(R.drawable.bluebg); 
    } 
else if (color.equals("#00cdb1")){ 
    background.setImageResource(R.drawable.redbg); 
    } 
+1

非常感謝快速回復,它的作品! –

+0

@GibranGul歡迎:) –