问题描述
我创建了一个新的应用程序依赖于默认的主详细流程的模板,在Android的工作室新建项目...对话框中选择。然后,我适应了适合我的需要,我的数据的应用程序。工作像手持设备和平板电脑的魅力。
我想才达到IST来自动选择列表中的第一项,显示详细视图,并设置列表项为选中的唯一的事情。
在的覆盖在onStart()方法ItemListFragment我所谓的onListItemClick(...)方法。这不得不下列行为:
- 当旋转装置中,在该列表中的第一项被选中(不是previously选择的一个)
- 列表项没有得到如在列表中选择标记
有人能指出我在如何实现这一目标的正确方向。因为我只希望在平板模式这种行为我想我必须把它放到ItemListActivity?
感谢
编辑:这是ItemListActivity
我的的onCreate方法 保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_item_list);
如果(findViewById(R.id.item_detail_container)!= NULL){
mTwoPane = TRUE;
((ItemListFragment)getFragmentManager()
.findFragmentById(R.id.item_list))
.setActivateOnItemClick(真);
}
}
您可以通过删除<$ C $的 onListItemClick(...)
呼叫解决此C>在onStart(...) ItemListFragment ,而是添加此片段以下为 setActivateOnItemClick年底(中> .. 。)
:
//如果在双窗格视图,pre-选择章节列表中的第一项
如果(activateOnItemClick&安培;&安培; mActivatedPosition == ListView.INVALID_POSITION){
。getListView()performItemClick(getListView(),0,getListView()getItemIdAtPosition(0));
}
此外,添加code的这一行,如果它已不存在,在 onListItemClick(...)
在 ItemListFragment
:
mActivatedPosition =位置;
请检查该文件的差异 ChapterListFragment
从我的GH回购这些提交昨天得到多一点背景下我的解决方案 - https://github.com/floydpink/BhagavadGita/compare/047de35c39f01c6341a7f677aa5b7cc47a7144a3...b1b45d15cd68290e2ebe909ca920bd7aefd2805e#diff-1
希望这有助于
I created a new app relying on the default "Master Detail Flow" template, chosen in the "New Project..." dialog of Android Studio. Then I adapted the application to fit my needs and my data. Works like a charm on handhelds and tablets.
The only thing I want to achive ist to autoselect the first item in the list, showing the detail view and setting the list item as selected.
In the "ItemListFragment" I called the "onListItemClick(...)" method in the overwritten "onStart()" method. This had following behaviours:
- When rotating the device, the first item in the list gets selected (not the previously selected one)
- The list item does not get marked as selected in the list
Could someone point me in the right direction on how to achieve this. Because I only want this behaviour in "Tablet-Mode" I guess I have to put it into the ItemListActivity?
Thanks
EDIT: This is my "onCreate" method of the "ItemListActivity"
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_list);
if (findViewById(R.id.item_detail_container) != null) {
mTwoPane = true;
((ItemListFragment) getFragmentManager()
.findFragmentById(R.id.item_list))
.setActivateOnItemClick(true);
}
}
You could resolve this by removing the onListItemClick(...)
call in the onStart(...)
of ItemListFragment
and instead adding this below snippet to the end of setActivateOnItemClick(...)
:
// If on dual-pane view, pre-select the first item from the chapter list
if (activateOnItemClick && mActivatedPosition == ListView.INVALID_POSITION) {
getListView().performItemClick(getListView(), 0, getListView().getItemIdAtPosition(0));
}
Also, add this one line of code if it is not already there in onListItemClick(...)
in ItemListFragment
:
mActivatedPosition = position;
Please check the diff on the file ChapterListFragment
from these commits yesterday on my GH repo to get a little more context to my solution - https://github.com/floydpink/BhagavadGita/compare/047de35c39f01c6341a7f677aa5b7cc47a7144a3...b1b45d15cd68290e2ebe909ca920bd7aefd2805e#diff-1
Hope this helps
这篇关于Android的主详细流程 - 在平板电脑列表中选择第一项只的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!