我有一个ListFragment并将其注册为上下文菜单,以便在长按列表中的项目时显示上下文菜单。
我在列表中有一个项目,当我点击它几秒钟时,一切正常,将出现上下文菜单。当我点击复制时,它应该执行一个动作。
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
//Display A Warning Before Removing A Playlist
final int currentIndex = info.position;
switch( item.getItemId() ) {
case DUPLICATE_ID:
duplicate( currentIndex ); //duplicate will be called
return true; //we will never get to this point
}
return super.onContextItemSelected(item);
}
//method that will be called
private void duplicate( int index ) {
DebugHelper.logDebug( "" + mItems.size() ); // returns 1
Playlist playlist = mItems.get( index ); //stops here
playlist.setPlaylistID( playlistCollection.getMaximumID()+1 );
//TODO:what if the file already exists?
Playlist.savePlaylistToFile( AudioUtils.PLAYLIST_DIRECTORY , String.valueOf( playlist.getPlaylistID() ), playlist );
playlistCollection.add(playlist);
Storage.getInstance().getPlaylistCollection().add(playlist);
//update list
((PlaylistListAdapter) getListAdapter()).notifyDataSetChanged();
}
永远不会调用return true;
语句,并且单击上下文菜单。将调用重复,但行mItems.get( index );
才会停止。调试器向我展示了几个类,最后在Looper类中停止,我无法阅读。
mItems
不是null
而且我没有收到任何错误。如果我在onContextItemSelected()
。
将要访问的类:
AbsListView(无源)
处理程序(无来源)
Looper(没有来源,它就在这里停止)
在某个地方,我看到一些主要线程没有暂停,但我再也找不到了。
更新:
在onCreate()方法中为ListFragmnent设置列表适配器后,我立即放置duplicate(0);
。它复制了第一个播放列表,我现在可以单击上下文菜单项。但是,我删除了所有播放列表,以便列表中只有一个项目,并且它再次无法工作....