能否保存并恢复Android 扩展式List View的状态(哪些物品已经倒塌,哪些没有倒塌)?
如果可能的话,我该怎么做呢?
我能访问Pause()/Resume()的扩展式List View吗? 如何访问?
能否保存并恢复Android 扩展式List View的状态(哪些物品已经倒塌,哪些没有倒塌)?
如果可能的话,我该怎么做呢?
我能访问Pause()/Resume()的扩展式List View吗? 如何访问?
透过各团体,拯救各团体,
int numberOfGroups = MyExpandableListViewAdapter.getGroupCount();
boolean[] groupExpandedArray = new boolean[numberOfGroups];
for (int i=0;i<numberOfGroups;i++)
groupExpandedArray[i] = MyExpandableListView.isGroupExpanded(i);
然后恢复国家:
for (int i=0;i<groupExpandedArray.length;i++)
if (groupExpandedArray[i] == true)
MyExpandableListView.expandGroup(i);
我不明白你的意思是,如何访问Pause()/Resume()中的ListView,如果将 ListView 对象作为活动类的成员存储,那么从那里应该可以访问。
改善Floaf的回答:宣布
public static int firstVisiblePosition=0;
暂停暂停
int numberOfGroups = MyExpandableListViewAdapter.getGroupCount();
boolean[] groupExpandedArray = new boolean[numberOfGroups];
for (int i=0;i<numberOfGroups;i++){
groupExpandedArray[i] = MyExpandableListView.isGroupExpanded(i);
}
firstVisiblePosition = MyExpandableListView.getFirstVisiblePosition();
续 续 续
for (int i=0;i<groupExpandedArray.length;i++){
if (groupExpandedArray[i] == true)
MyExpandableListView.expandGroup(i);
}
MyExpandableListView.setSelection(firstVisiblePosition );
这将不仅恢复每个组的状态, 还会滚动到活动暂停时所看到的“ 儿童视图 ” 。
更简单的方法可能是, 如果你再使用 SetOn GroupClickListner 和 setOnChildClickLickLister 只保留最后选择的儿童视野和组合Positin整数, 然后再检查它并做出正确回应,
if (childPosition > 0) {
mExpandableList.expandGroup(groupPositin);
}
mExpandableList.setItemChecked(groupPositin + childPosition , true);
您只需在 SetOn GroupListener 方法中记住将儿童位置设为 0 。
我遇到同样的问题,找到了更好的答案。我有一个碎片,用“强势”的“强力”的“拯救Instance State 强”和“强势”的“强势”的“恢复状态 强”来拯救和恢复“强势”的“扩大的ListView 强”。
我在这里保存列表状态
@Override
public void onSaveInstanceState( @NonNull Bundle outState )
{
super.onSaveInstanceState( outState );
ExpandableListView expandable = getView() != null ? getView().findViewById( R.id.expandable ) : null;
if( expandable != null )
{
int groupsCount = expandable.getExpandableListAdapter()
.getGroupCount();
boolean[] groupExpandedArray = new boolean[groupsCount];
for( int i = 0; i < groupsCount; i += 1 )
{
groupExpandedArray[i] = expandable.isGroupExpanded( i );
}
outState.putBooleanArray( "groupExpandedArray", groupExpandedArray );
outState.putInt( "firstVisiblePosition", expandable.getFirstVisiblePosition() );
}
}
在这里,我恢复它 当需要它的时候 它们>
@Override
public void onViewStateRestored( @Nullable Bundle savedInstanceState )
{
super.onViewStateRestored( savedInstanceState );
if( savedInstanceState != null )
{
boolean[] groupExpandedArray = savedInstanceState.getBooleanArray( "groupExpandedArray" );
int firstVisiblePosition = savedInstanceState.getInt( "firstVisiblePosition", -1 );
ExpandableListView expandable = getView() instanceof ViewGroup ? getView().findViewById( R.id.expandable ) : null;
if( expandable != null && groupExpandedArray != null )
{
for( int i = 0; i < groupExpandedArray.length; i++ )
{
if( groupExpandedArray[i] )
expandable.expandGroup( i );
}
if( firstVisiblePosition >= 0 )
expandable.setSelection( firstVisiblePosition );
}
}
}
I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...
I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...
I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...
I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...
To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?
When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...
I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...
I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...