0

I have an application with 3 fragments, and in Fragment 1 you can select a vehicle from a list of vehicles.

I want the application to automatically select the same vehicle when I switch to Fragment 3, without me pressing on the actual vehicle item in that Fragment's list.

So say I am in Fragment 1 and I press on vehicle 111. If I now switch to Fragment 3 (which has its own vehicle list, populated with the same vehicles), I want the application to automatically select vehicle 111 for me, so I can see its parameters and so on.

In other words, I want to artifically generate an onClick event and pretend I clicked on that bus again, in this Fragment 3.

How can I do this?

Robert Ruxandrescu
  • 627
  • 2
  • 10
  • 22

1 Answers1

0

Find postion of that item and simply do

listView.getAdapter().getView(position, null, null).performClick();
Kishore Jethava
  • 6,666
  • 5
  • 35
  • 51
  • I tried it, but it doesn't work. Instead, it kind of works like this: `vehicleListView.performItemClick(vehicleListView.getSelectedView(),RealTimeFragment.selectedBus,vehicleListView.getItemIdAtPosition(RealTimeFragment.selectedBus));` I'm using three static int variables to remember the view, position and id of the item in the previous fragment. And, by the way, it doesn't work in any way until you initialize the fragment for the first time. – Robert Ruxandrescu Apr 13 '17 at 13:47