我在我的应用程序中使用 NavigationDrawer,我想知道我是否有可能像按钮一样在某些抽屉导航列表项上执行单击?
slideMenuItems = new ArrayList<NavDrawerModel>();
slideMenuItems.add(new NavDrawerModel("People"));
slideMenuItems.add(new NavDrawerModel("Products"));
slideMenuAdapter = new NavDrawerAdapter(getApplicationContext(), R.layout.drawer_list_item, slideMenuItems);
drawerList.setAdapter(slideMenuAdapter);
drawerList.setOnItemClickListener(new SlideMenuClickListener());
private class SlideMenuClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Do some stuff here
}
最佳答案
调用performItemClick
在 ListView
public boolean performItemClick (View view, int position, long id)
Added in API level 1
Call the OnItemClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.
Parameters
view The view within the AdapterView that was clicked.
position The position of the view in the adapter.
id The row id of the item that was clicked.
Returns
True if there was an assigned OnItemClickListener that was called, false otherwise is returned.
使用方法:
int position = 5;
listView.performItemClick(
yourAdapter.getView(position, null, null),
position,
yourAdapter.getItemId(position)
);
如果您使用自定义适配器,请记住正确覆盖 getItemId
!
关于android - NavigationDrawer - 是否可以以编程方式模拟(执行)点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24267155/