当用户单击要调用对话框的按钮时 - 该对话框包含 ListView 中的产品列表。用户选择产品后,它应该进入上一个 Activity 。
我已经使用 startActivityForResult () 完成了。
有一些问题。我的调用 Activity 在正常标签 Activity 中,正常标签 Activity 在标签 Activity 组中。
实际上我想在 drrop down(Spinner) 中做。在我的 scanerio 中我无法获取上下文。它 awalys 给 Android Spinner Error : android.view.WindowManager$BadTokenException: Unable to add window
所以我对我的设计进行了这样的更改:当用户单击按钮时,它会在 ListView 中加载产品列表。选择产品后,它会返回到之前的 Activity 。
This is my previous question : link
这里调用 Activity :
//Click Product button
l_prod.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent showContent = new Intent(LineDiscountActivity.this,ListProductActivity.class);
Bundle bundle = new Bundle();
bundle.putString("Activity", "LineDiscountActivity");
bundle.putString("RetailerName", retailerName);
bundle.putString("RetailerCode", retailerCode);
showContent.putExtra("discountProduct", discountList);
showContent.putExtras(bundle);
getParent().startActivityForResult(showContent, 5);
}
});
还有我的接收器 Activity :
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Object o = this.getListAdapter().getItem(position);
String book = o.toString();
Intent i = new Intent();
Bundle bundle = new Bundle();
bundle.putString("Activity", "ListProductActivity");
bundle.putString("RetailerName", retailerName);
bundle.putString("RetailerCode", retailerCode);
bundle.putString("seletcedProductCode", products.get(position).getProductCode());
bundle.putString("seletcedProductName", products.get(position).getDescription());
bundle.putDouble("seletcedProductQty", products.get(position).getAvailableQuantity());
i.putExtra("discountProduct", discountList);
i.putExtras(bundle);
if (getParent() == null) {
setResult(Activity.RESULT_OK, i);
} else {
getParent().setResult(Activity.RESULT_OK, i);
}
ListProductActivity.this.finish();
}
和通话 Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
Log.i("-requestCode from LineDisocunt--" ,"" + requestCode);
}
我已经在调用 Activity 和 Tab 主 Activty 中编写了这段代码 (onActivityResult)。
我哪里都没去..
onActivityResult mehtod.But it didn't go it.
我的代码有什么问题。
如果有人知道请告诉我...
提前致谢
最佳答案
当我将 startActivityForResult() 与 activity group 一起使用时,我遇到了同样的问题。
您的 Activity 结果将进入您的 Activity 组。您不会在您的第一个 Activity 中获得 Activity 结果
所以你可以通过在你的第一个 Activity 中使用一个公共(public)静态对象来解决这个问题,当你调用第二个 Activity 时,你必须从第二个 Activity 中分配你的第一个 Activity 对象。然后完成第二个 Activity ,这样你的第一个 Activity 就会恢复并且您可以通过覆盖第一个 Activity 中的 onResume() 方法来更新您的用户界面。您必须检查是否分配了对象的验证天气。
例如
您的第一个 Activity 中有一个静态对象产品
第一个 Activity
public static Product product;
start second activity
startactivity(this, SecondActivity.class);
don't finish First Activity
您必须覆盖onResume() 方法然后您可以使用由第二个 Activity 分配的产品对象
第二个 Activity
FirstActivity.product.setName(name);
FirstActivity.product.setPrice(price);
分配产品对象后,您必须完成第二个 Activity 喜欢
finish()
编辑
我得到了你的 badTokenException 问题的解决方案
解决方法
关于android - startActivityForResult 似乎没有调用 onActivityResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7645489/
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r