gpt4 book ai didi

java - 在使用空 while 循环初始化 fragment 之前等待抽屉导航关闭

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:32:08 24 4
gpt4 key购买 nike

根据DrawerLayout文档,“避免在动画期间执行昂贵的操作,例如布局,因为它会导致卡顿”。

因此,我尝试等待抽屉关闭后再继续:

@Override public void onItemClick(AdapterView parent
, View view
, int position
, long id) {
// Close the drawer
mDrawerLayout.closeDrawer(mDrawerList);

ExecutorService es = Executors.newSingleThreadExecutor();
final int mPosition = position;
Thread navThread = new Thread(new Runnable() {
@Override public void run() {

// Wait for the drawer to close
while (mDrawerLayout.isDrawerOpen(mDrawerList));

// Initialize the Fragments.
runOnUiThread(new Runnable() {
@Override public void run() {
selectNavigationItem(mPosition);
}
});
}
});
es.submit(navThread);
es.shutdown();
}

即使它有效,Lint 也会警告我有关空 while 循环的信息。如果没有空的 while 循环,我如何才能实现这种效果?

最佳答案

ListView.OnItemClickListener 中:

@Override public void onItemClick(AdapterView parent
, View view
, int position
, long id) {
mPosition = position;
mNavigationItemClicked = true;
mDrawerLayout.closeDrawer(mDrawerList);
}

DrawerLayout 中:

public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
if (mNavigationItemClicked)
selectNavigationItem();
mNavigationItemClicked = false;
}

selectNavigationItem() 中:

switch (mPosition) {
...
}

关于java - 在使用空 while 循环初始化 fragment 之前等待抽屉导航关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20083838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com