问题描述
我有一个使用导航抽屉的应用程序,该应用程序提供位置列表.在抽屉中,用户可以先设置几个选项(例如选择国家/地区,城市等),然后在主要活动中显示相应的列表.
I have an application using navigation drawer that provides list of locations. In the drawer, there are several options (like choosing country, city, etc) that user can setup before showing the corresponding list in the main activity.
当用户关闭抽屉时,是否有可能刷新列表,或者还有另一种方法可以解决此问题?我尝试搜索教程,但未发现有关此抽屉式封闭侦听器的任何信息.任何建议都会有所帮助,谢谢!
Is there any possibility to refresh the list when user close the drawer, or maybe there is another way to solve this? I've tried to search for tutorials but found nothing about this drawer closed listener.Any suggestions would be helpful, thanks!
推荐答案
设置ActionBarDrawerToggle
时,您可以实现" onDrawerClosed
和onDrawerOpened
回调.请参见文档
When you setup the ActionBarDrawerToggle
you can "implement" the onDrawerClosed
and onDrawerOpened
callbacks. See the following example from the Docs:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
// Do whatever you want here
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
// Do whatever you want here
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.addDrawerListener(mDrawerToggle);
现在不建议使用setDrawerListener,而应使用addDrawerListener.
Now the setDrawerListener is deprecated, use addDrawerListener instead.
这篇关于抽屉上的Android关闭监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!