I have a problem whith custom adapter view.
I try, change background of view
on Click
event.
I have AdapterView.OnItemClickListener
, where i get selected item, and calling myListView.invalidate();
After invalidate, calling adapters getView(...)
. Here code for this:
@Override public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ProjectAdapterData projectItem;
if (row == null) {
LayoutInflater inflater = LayoutInflater.from(context);
row = inflater.inflate(R.layout.project_small_item_layout, null);
ProjectAdapterData projectAdapterData = new ProjectAdapterData();
row.setTag(projectAdapterData);
name = (TextView)row.findViewById(R.id.txtObjectName);
if (objectData[position].Name!= null)
name.setText(objectData[position].Name);
adress = (TextView)row.findViewById(R.id.txtObjectAdress);
if (objectData[position].Adress != null)
adress.setText(objectData[position].Adress);
}
else {
background = (RelativeLayout)row.findViewById(R.id.rlProjectBackground);
if (objectData[position].isSelected)
background.setBackgroundColor(context.getResources().getColor(R.color.cProjectSelected));
else
background.setBackgroundResource(R.color.cProjectUnSelected); //it's calls, but no result
row.invalidate();
}
return row;
}
My question, why background doesn't change?
My selector_list
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:color="@color/cProjectSelected"/>
<item android:state_selected="false"
android:color="@color/cProjectUnSelected"/>
</selector>