android:从选项卡结束活动
我有 3 个类,我们称它们为 1、2 和 3。
类 1 扩展了 TabActivity 并组织了整个选项卡,类 2 和类 3 只是两个单独的选项卡,每个选项卡都有一些文本行。我使用 startActivityForResult 从另一个活动调用 Class 1。
然后,我在类 2 中添加了一个 optionsMenu,当用户单击该 optionMenu 时,将执行以下代码:
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
Intent i = new Intent();
switch(item.getItemId()) {
case Result.NEXT_ID:
i.putExtra(Result.PAGE_REQUEST, NEXT);
setResult(RESULT_OK, i);
finish();
break;
case Result.PREV_ID:
i.putExtra(Result.PAGE_REQUEST, PREV);
setResult(RESULT_OK, i);
finish();
}
return super.onMenuItemSelected(featureId, item);
}
在我的父类(首先调用 1 的类)中,在其 onActivityResult 函数中,我想从额外的。然而,意图总是空的,我不明白为什么。
当我在类 2 上调用 finish() 时,它是否调用了类 1 中的其他函数?我是否必须以某种方式传输意图数据?
这是startactivityforresult,Result is Class 1
private void getResult(String result) {
Intent i = new Intent(this, Result.class);
i.putExtra(RESULT, result);
i.putExtra(PAGE, curr_start_page);
startActivityForResult(i, 0);
}
我也尝试将optionmenu方法放在Class 1中,但是,当我调用finish()时,它不执行任何操作。
编辑:
我认为我应该将选项菜单放在第 1 类中,因为我在 startActivityForResult 中启动第 1 类。但是如何退出选项卡布局呢?在类 1 中调用 finish() 似乎并不能解决问题。
I have 3 classes, let's call them 1, 2, and 3.
Class 1 extends TabActivity and organizes the whole tab thing, Class 2 and 3 are just two separate tabs each with some lines of text. I call Class 1 from another activity using startActivityForResult.
I then added an optionsMenu in class 2, and when user clicks the optionMenu, the following code is carried out:
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
Intent i = new Intent();
switch(item.getItemId()) {
case Result.NEXT_ID:
i.putExtra(Result.PAGE_REQUEST, NEXT);
setResult(RESULT_OK, i);
finish();
break;
case Result.PREV_ID:
i.putExtra(Result.PAGE_REQUEST, PREV);
setResult(RESULT_OK, i);
finish();
}
return super.onMenuItemSelected(featureId, item);
}
In my parent class (the class that called 1 to begin with), in its onActivityResult function, I want to get the data from the extras. However, the intent is always null, and I can't figure out why.
When I call finish() on class 2, is it calling some other function in class 1? Do I have to transfer the intent data somehow?
Here's the startactivityforresult, Result is Class 1
private void getResult(String result) {
Intent i = new Intent(this, Result.class);
i.putExtra(RESULT, result);
i.putExtra(PAGE, curr_start_page);
startActivityForResult(i, 0);
}
I also tried to put the optionmenu methods in Class 1, however, when I call finish(), it doesn't do anything.
Edit:
I think I should put optionsmenu in Class 1, since im starting class 1 in startActivityForResult. But how do I exit out of a tab layout? calling finish() in class 1 doesn't seem to do the trick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚拿到。在类 2 的 optionsmenu 方法中,我需要
调用 finish() ,它可以正常工作。
I just got it. In the optionsmenu method in class 2, I need to do
then call finish(), it works correctly.
在类 1 中,通过对收到的任何内容执行
setResult
来重写 onActivityResult 并实现它。看看这是否有效。
您正在尝试将值从 2 发送到 1 的父级。但是当类 2 完成时,它只是将其值发送给类 1。我不认为类 1 会将此值返回给其调用者。
In class 1, override a onActivityResult and implement it, by doing a
setResult
with whatever you received.See if this works.
You're trying to send a value from 2 to 1's parent. But when class 2 finishes, it is just sending its value to class 1. I don't think class 1 is returning this value to its caller.