I'm trying to create a custom listview row color inside my adapter
Here is my xml
artists_list_backgroundcolor
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:color="#6495ED" />
<item android:state_pressed="true"
android:color="#ffffff" />
<item android:state_selected="true"
android:state_pressed="false"
android:color="#E5F5FA" />
</selector>
and here is my code inside adapter
public override View GetView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if (row == null)
{
row = LayoutInflater.From(mContext).Inflate(Resource.Layout.CategoryPreview, null, false);
}
TextView txtCategoryName = row.FindViewById<TextView>(Resource.Id.txtCategoryName);
txtCategoryName.Text = mitems[position].CategoryName;
TextView txtCategoryID = row.FindViewById<TextView>(Resource.Id.txtCategoryID);
txtCategoryID.Text = mitems[position].CategoryID;
row.SetBackgroundResource(Resource.Drawable.artists_list_backgroundcolor);
return row;
}
When activity is going to start i'm getting error
Android.Content.Res.Resources+NotFoundException: Drawable WiOrderAndroid.WiOrderAndroid:drawable/artists_list_backgroundcolor with resource ID #0x7f020053
It work only if i will set my xml with this way.
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#ef4444" />
</shape>
</item>
</selector>
But is this the right way?