• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Programmatic 'Touch' vs Physical Touch

Dhugalmac

Lurker
Jun 26, 2015
1
0
I have tried quite a few suggestions and am still coming up short.

I have a Listview with 100+ Items.
When I select a single Item I want the Background Color to change so as to visually indicate Selection.
I have set up the Item Selector for the items to show State-specific Colors
These settings are
<item android:state_selected="false" android:drawable="@color/orange_500" />
<item android:state_pressed="false" android:drawable="@color/blue_500" />
<item android:state_focused="false" android:drawable="@color/green_500" />
<item android:state_active="false" android:drawable="@color/red_600" />
<item android:state_checked="false" android:drawable="@color/purple_500" />
When I do a physical Touch - things work as intended.
When I do a programmatic 'Touch' - the Listview scrolls to the intended item (as intended), but the Background Color does not change

When the programmatic 'Touch' is done (via Voice Recognition) the following is currently being done:
1. The ListView data source is searched for a matching item and if found, the ListView's Item ID is determined.
2. With a matchingLotID the following commands are executed:
ListView.setItemChecked(matchingLotID,true);
Listview.setSelection(matchingLotID);
Listview.setPressed(true);
Listview.performItemClick( the associated parameters here );
3. Now that launches the associated setOnItemClickListener() method which in turn launches the setOnItemClick() method
4. That again issues the setSelected() setPressed() commands.

When in development Debug more I can watch the setOnItemClick() method execute for a physical Touch - again = everything works fine. The Background Color changes as intended
Then when I watch the same code executed for the programmatic 'Touch' the Background Colors does NOT change.

I am baffled (mostly because I am an Android 'greenhorn')
What am I missing?

Thanks
DhugalMac
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones