I have a ListView populated with custom XML ListItems, this is the XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
...
</RelativeLayout>
The listView shows correctly on screen and if i click or hold on an item it becomes blue (I'm using Holo Light Theme)
the problem comes when i try to assign an OnClickListener to the view, inside getView in my Activity that extends BaseAdapter:
@Override
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
...
convertView = InflateUtils.inflate(mContext, R.layout.list_item);
...
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(mContext, "Test", 2000).show();
}
});
...
}
after doing that, the list item highlight color is no more shown, when i click or hold on a list item it's background stays white, anyway the onClickListener is perfectly working.
Do you have any suggestion to get the highlight color while keeping the default styles of HoloLight?
You may want to use OnItemClickListener
on the ListView
itself, instead of separate click listeners for item views.
Also, highlight problem has already been described here: Android listview no longer highlights selection onclick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With