- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在学习 android 编程,并且在主/详细 fragment 中的向上导航有问题。为了练习,我正在整理一个应用程序来跟踪 Composer 为我妻子的合唱团的乐谱库编写的乐谱。 (非常深奥,但如果我能让它工作,我将对 Android 编程有更好的理解。)
第一个屏幕是 Composer 列表。从列表中选择一个在详细信息 fragment 中显示有关 Composer 的详细信息;这工作得很好。
我有这样创建的细节 fragment :(直接来自 eclipse 提供的模板)
//In ComposerListActivity.java
public void onItemSelected(String id) {
if (mTwoPane) {
// In two-pane mode, show the detail view in this activity by
// adding or replacing the detail fragment using a
// fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(ComposerDetailFragment.ARG_ITEM_ID, id);
ComposerDetailFragment fragment = new ComposerDetailFragment();
fragment.setArguments(arguments);
getFragmentManager()
.beginTransaction()
.replace(R.id.composer_detail_container, fragment)
.commit();
} ...
}
Detail fragment 显示有关 Composer 的信息(姓名、出生/死亡日期、简历等)以及一个用于查看该 Composer 创作的作品的按钮。按下该按钮会调出另一个主/从 Activity :
//In ComposerDetailFragment.java
protected void viewPieces() {
Intent intent = new Intent(this.getActivity(), PieceListActivity.class);
intent.putExtra(COMPOSER_ID, this.dataObject.getId());
this.getActivity().startActivityForResult(intent, VIEW_PIECES_LIST);
}
这很好用,并显示了该 Composer 创作的作品列表。您可以选择其中一首曲子,它会显示有关该曲子的信息(标题、部分数、键、页数等)。如果我从这些曲子中按“返回”,它会带我回到 Composer 列表选择了先前选择的 Composer 。但是,如果我按“向上”(在操作栏中的图标上),它会将我带到一个显示空白详细信息 fragment 的 Activity ( Composer 的 ID 丢失)。在这种情况下,我希望 back 和 up 的功能相同——它们都应该上升一个级别(对于 Composer 列表的作品列表)。然而,在手机上,它应该做它正在做的事情(除了保留 Composer ID,但我怀疑这是一个单独的问题)。
//In PieceListActivity.java
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
我需要做什么才能做到这一点?我应该在这里完全放弃向上导航,因为返回似乎在做我想做的事,还是有办法让它做我想做的事?我在这里找到的所有问题/答案似乎都没有解决这种情况,尽管有一些很接近(而且我似乎被圈在了其中一些上)。
提前致谢。
最佳答案
在 ComposerListActivity
的 onItemSelected(String id)
中:
if (mTwoPane) {
Bundle args = new Bundle();
args.putString(ComposerDetailFragment.ARG_ITEM_ID, id);
ComposerDetailFragment fragment = new ComposerDetailFragment();
fragment.setArguments(args);
getFragmentManager().beginTransaction().replace(R.id.composer_detail_container, fragment).commit();
}
在 ComposerDetailFragment
的 viewPieces
中:
Intent i = new Intent(getActivity(), PieceListActivity.class);
intent.putExtra(ARG_ITEM_ID, getArguments().getString(ARG_ITEM_ID));
startActivityForResult(i, VIEW_PIECES_LIST);
在 PieceListActivity
的 onOptionsItemSelected
中:
case android.R.id.home:
// Add id of detail fragment as extra to intent on task stack before navigating up
Intent upIntent = NavUtils.getParentActivityIntent(this);
String id = getIntent().getStringExtra(ComposerDetailFragment.ARG_ITEM_ID);
upIntent.putExtra(ComposerDetailFragment.ARG_ITEM_ID, id);
NavUtils.navigateUpTo(this, upIntent);
return true;
在 ComposerListActivity
的 onCreate
中:
String id = getIntent().getStringExtra(ComposerDetailFragment.ARG_ITEM_ID);
if (id != null) onItemSelected(id);
关于android - 用完导航时如何使用主/详细信息 fragment 返回到父列表 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19594250/
我试图找到在庞大的代码库中创建 NaN 的位置。是否有一些编译器标志或我可以用来在 NaN 上 panic 的东西,这样我就可以找到它在哪一行? 最佳答案 没有编译器标志。你能做的最好的事情就是把你的
A类 class ClassA { @Autowired class ClassB; } 类配置: @Configuration class TestConfi
我是一名统计学研究生,经常使用 R。我熟悉其他编程环境中的 OOP。我什至在各种定义用于存储数据的新类的统计包中看到了它的使用。 在我研究生生涯的这个阶段,我通常会为一些类作业编写一些算法——一些接收
我想要两个不同的网络摄像头视频输出,一个是普通的网络摄像头镜头,另一个是它的“镜像”版本。 cv2可以吗? import time, cv2 video=cv2.VideoCapture(0) a=0
我创建了一个可以通过两种方式过滤的图库。一个通过单击按钮,另一个通过搜索过滤器。过滤器工作完美,除了当 div 隐藏在过滤器上时,其余显示的 div 不会彼此相邻 float 。 这是过滤前的样子:
我们作为一个 4 人团队工作,我们的项目部署在 openshift我们使用 git 存储库 进行提交、推送和 pull 。当有人提交更多更改时,其他人必须 pull 它以在我们的系统中进行更新。但是从
我正在尝试扩展自动完成功能,以便在选择某个项目时显示辅助标签。例如,给定显示项目的自动完成功能,项目名称将显示在包含代码的输入框旁边的 span 标记中。 查看自动完成源代码,我发现过滤值的下拉列表是
我有一个包含歌曲、艺术家和专辑实体的核心数据。 歌曲有可选的一对一关系艺术家到艺术家实体和专辑到专辑实体这两个实体都与 Song 实体具有反向关系。 相册有可选的一对一关系艺术家到艺术家实体和可选的一
XmlSerializer正在调用 IList.Add()在我的课上,我不明白为什么。 我有一个自定义类(层次结构中的几个类之一),其中包含我使用 XmlSerializer 与 XML 相互转换的数
我们在 Web 应用程序中定义了此事件,它创建了一个名为 timelineEventClicked 的自定义触发器 canvas.addEventListener('click', function
有大量资源可用于使用 Swift(可达性)检查有效的 Internet 连接,以及在进行 API 调用时检查 httpResponse 的 statusCode 的方法,但是检查和处理这些的“正确”方
谁能告诉我是否可以在 Controller 规范中 stub params[] 值,以便 Controller 接受 stub 值作为 View 中的实际 params[] 值。 例如,我的观点有一个
我的问题是没有在 UserControl 中连接 DependencyProperties。这不是问题。当我将 UserControl 中的按钮绑定(bind)到 UserControl 的 Depe
如何#define 路径 L"C:\Windows\System32\taskmgr.exe"来处理宽字符 #define TASK_MGR "C:\\Windows\\System32\\taskm
我正在尝试使用 Jasmine 和 Sion 编写单元测试,但是在使用 RequireJs 加载模块时我很难找到以下等效项: sinon.stub(window, "MyItemView"); 使用
我有一个包含三个 div 的示例页面,如下所示: 当浏览器大小达到 md 点并且第二个 div 高于第一个 div 时,第三个 div 开始在第一个的右侧
我在 C++ 端有 CString cs,在 C# 端有 IntPtr ip,它通过编码(marshal)处理机制包含 cs 的值。 然后,我只需将需要的字符串作为 Marshal.PtrToStri
我是一名优秀的程序员,十分优秀!