"I want everybody to know I remain optimistic that we're going to get this done," he said, according to video of his remarks. He said passage of an immigration bill was "more a question of when than if."
"But I'd rather get this done sooner rather than later," Obama said.
The White House issued a statement after the approximately 40-minute visit that said Obama thanked the hunger strikers "for their sacrifice and dedication and told them that the country is behind them on immigration reform."
Organizers of the fast said Obama expressed concern for the health of the hunger strikers, and held the shoe of an immigrant who died in the Arizona desert while trying to enter the U.S.
House Speaker John Boehner, R-Ohio, has refused to schedule a vote on a comprehensive immigration measure the Senate passed this summer. The House prefers a piecemeal approach, but Boehner hasn't said whether lawmakers will consider any bills this year or whether the issue will slip into next year, when midterm-election politics will make legislative action less likely.
The House has moved too slowly to satisfy immigration advocates, including those on the hunger strike as well as a man who shouted during Obama's speech in California for the president to stop separating families by deporting people who are living in the country illegally.
Obama was the latest administration official to visit with the activists. Vice President Joe Biden, Cabinet secretaries and top White House advisers have also visited.