On Android 2.3 when you click on one item in the list selects the entire ListView the same color as the one item in the list. I use custom selector.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/transparent" />
<item android:state_focused="true"
android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/color_press" />
<item android:state_focused="true"
android:state_enabled="false"
android:drawable="@drawable/color_press" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/color_press" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/color_press" />
<item android:state_focused="true"
android:drawable="@drawable/color_press" />
</selector>
ListView in xml.
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#B7B7B7"
android:dividerHeight="1px"
android:listSelector="@drawable/list_view_selector" />
What a problem?
UPD:
my custom Adapter
public class CityAdapter extends ArrayAdapter<CityInfo>
{
private boolean isRus = false;
private LayoutInflater inflater;
public CityAdapter(final Context context, final List<CityInfo> objects)
{
super(context, -1, objects);
isRus = context.getString(R.string.locale).equalsIgnoreCase("ru");
inflater = LayoutInflater.from(context);
}
private class ViewHolder
{
RadioButton radioButton;
TextView textView;
}
@Override
public View getView(final int position, View convertView, final ViewGroup parent)
{
ViewHolder holder;
if (convertView == null)
{
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.welcome_city_case_list_item, null);
holder.radioButton = (RadioButton) convertView.findViewById(R.id.radioButton);
holder.textView = (TextView) convertView.findViewById(R.id.size);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
final CityInfo cityInfo = getItem(position);
holder.radioButton.setText(isRus ? cityInfo.getRus() : cityInfo.getEng());
holder.textView.setHint(cityInfo.getVisibleZipSize());
return convertView;
}
}
and welcome_city_case_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:focusable="false"
android:clickable="false"
>
<RadioButton
android:id="@+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:textColor="@color/black"
android:duplicateParentState="true"
style="@style/CustomRadioButton"
android:text="Екатеринбург"
android:layout_weight="1"
android:paddingTop = "10dp"
android:paddingBottom = "10dp"
android:clickable="false"
android:focusable="false"
android:background="@color/transparent"
/>
<TextView
android:id="@+id/size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:hint="2,1MB"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:focusable="false"
/>
</LinearLayout>