我正在为一个 Android 应用程序设计屏幕,其中屏幕设计是主从流程,左侧是 ListView ,右侧是变化的表单(类似于 HTML 中的向导设计)
我注意到第一次创建屏幕时,屏幕右侧是空的,直到我手动“点击”第一个项目,然后它只会加载第一个 fragment 。我的问题是,我是否可以默认加载第一项?
我曾尝试在 ListFragment 类的 onViewCreated 函数中添加以下代码。它将显示右侧屏幕,但左侧没有 ListView 。
getListView().requestFocusFromTouch();
getListView().setSelection(position);
getListView().performItemClick(getListView().getAdapter().getView(position, null, null), position, position);
有人知道怎么做吗?
谢谢。
最佳答案
最后我设法使用下面的代码让事情正常进行:
fragment.getListView().requestFocusFromTouch();
fragment.getListView().setSelection(position);
fragment.getListView().performItemClick(fragment.getListView().getAdapter().getView(position, null, null), position, position);
关于android - 默认情况下选择主从流程中的第一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19132007/