如何更改LinearLayout的背景,它是在Android的游标适配器中定义的



我有一个游标适配器和一个自定义布局。我想要基于的价值

String result = cursor.getString(cursor.getColumnIndex(cursor.getColumnName(5)));

我的线性布局有不同的背景,我试图在我的光标适配器和bindView中更改它,比如:

LinearLayout LinearGameItem = (LinearLayout) view.findViewById(R.id.LinearItem);
    if(result.contains("Win"))
    {
        LinearGameItem.setBackgroundColor(Color.parseColor("#F3FCDA"));
    }

我得到一个错误

java.lang.NullPointerException: Attempt to invoke virtual method
'void android.widget.LinearLayout.setBackgroundColor(int)' 
on a null object reference 
at com.cfriends.contacts.model.CursorAdapter.bindView

我刚刚注意到线性布局的id在600sw-dp和700sw-dp处为空,所以我为每个布局放置了相同的id

最新更新