在Android对话框后创建另一个对话框(Creating another dialog after dialog Android)
在学习使用Android应用程序中的对话框时,我创建了这个对话框:
dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setTitle("Title"); dialogBuilder.setPositiveButton("Next", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "Next dialog", Toast.LENGTH_LONG).show(); } }); dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "Canceled", Toast.LENGTH_LONG).show(); } }); AlertDialog dialog = dialogBuilder.create(); dialog.show();
如何在按下“下一步”后立即创建另一个对话框? 我看过这篇文章,但我不明白那里的答案。
While learning to use dialogs in an Android app I've created this dialog box:
dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setTitle("Title"); dialogBuilder.setPositiveButton("Next", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "Next dialog", Toast.LENGTH_LONG).show(); } }); dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "Canceled", Toast.LENGTH_LONG).show(); } }); AlertDialog dialog = dialogBuilder.create(); dialog.show();
How to create another dialog immediately after "Next" is pressed? I've read this post but I don't understand the code answered there.
原文:https://stackoverflow.com/questions/41160982
最满意答案
类名称如InvoiceReader,PriceCalculator,MessageBuilder,ArticleReader,InvoiceReader实际上并不是动词名称。 他们真的是“名词名词”的名字。 见代理名词
动词类的名字将类似于验证,操作,管理等。显然,这些更好地用作方法,并且作为类名称将是相当尴尬的。
“名词代理名词”类名称的最大问题在于它们对于该类什么是实际的(例如UserManager,DataProcessor等)可以给出很少的意义。 因此,他们更有可能blo肿,失去内在的凝聚力。 (见单一责任原则 )。
因此,具有IInvoiceReader和IArticleReader接口的WebService类可能是更清晰和更有意义的OO设计。
这给你一个简单的,明显的名词类名“WebService”,以及“名词代理名词”接口名称,清楚地宣告WebService类可以为呼叫者做什么。
您可能还可以通过前缀另一个名词(例如PaymentWebService)为实际类赋予更多意义。
然而,界面总是比单一的类名更好地描述该类可以为呼叫者做什么。 随着课程越来越复杂,新界面也可以添加有意义的名称。
Class names like InvoiceReader, PriceCalculator, MessageBuilder, ArticleReader, InvoiceReader are not actually verb names. They are really "noun agent-noun" class names. See agent nouns.
A verb class name would be something like Validate, Operate, Manage etc. Obviously these are better used as methods and would be quite awkward as class names.
The biggest problem with "noun agent-noun" class names is that they can give very little meaning as to what the class actually does (eg UserManager, DataProcessor etc). As a result they are more likely to be bloated and to lose internal cohesion. (See Single Responsibility Principle).
Therefore the WebService class with the IInvoiceReader and IArticleReader interfaces is probably the clearer and more meaningful OO design.
This gives you the simple, obvious noun class name "WebService", along with "noun agent-noun" interface names that clearly advertise what the WebService class can do for callers.
You could probably also give more meaning to the actual class by prefixing another noun, for example PaymentWebService.
However the interfaces are always better than a single class-name at describing more specifically what the class can do for callers. As the class grows more complex, new interfaces can also be added with meaningful names.
相关问答
更多-
避免的类(代码完成)(Classes to avoid (code complete))[2024-03-09]
类名称如InvoiceReader,PriceCalculator,MessageBuilder,ArticleReader,InvoiceReader实际上并不是动词名称。 他们真的是“名词名词”的名字。 见代理名词 动词类的名字将类似于验证,操作,管理等。显然,这些更好地用作方法,并且作为类名称将是相当尴尬的。 “名词代理名词”类名称的最大问题在于它们对于该类什么是实际的(例如UserManager,DataProcessor等)可以给出很少的意义。 因此,他们更有可能blo肿,失去内在的凝聚力。 (见 ... -
我们应该避免为完整的程序打开警告吗?(Should we avoid turning on warnings for the complete program? [closed])[2021-11-11]
你已经很准确地描述了情况。 -w在全局范围内启用警告(跨所有模块,除非它们特意将其关闭)。 use warnings表现为词法,不会影响其他模块中发生的情况。 话虽如此,我不认为这是一个更好的问题。 这真的是你想要的行为的问题。 我们不会说foreach比不知道断言的上下文更好。 如果您希望在全球范围内开启警告的行为,尽一切办法。 如果您想以不影响外部模块的方式打开警告,请执行此操作。 警告,在我看来,是一个开发和调试工具。 我试着总是用“on”(在我自己的代码中)的警告进行编程。 不管我是否将代码部署到启 ... -
我可以避免为从接口派生的类编写样板代码吗?(Can I avoid writing boilerplate code for classes that derive from an interface?)[2021-12-15]
为了使讨论更具体一点,并且由于评论中的空间有限,类似下面的内容会对您有用还是不适用? type ModelArg = { Number: int Name: string } type IModel(modelArg: ModelArg) = abstract member Number: int abstract member Name: string default __.Number = modelArg.Number default __ ... -
事实上,这种数据库代码模式经常出现,但也有缺点。 最好使用DataSource并以XML或属性声明性地存储多个数据源。 (与开发/生产不同)。 使用这种DataSource的一种方法是使用CDI,依赖注入。 然后,您仍然可以自由地通过测试数据源创建单元测试。 开放/关闭级别和执行功能也很诱人,但是try-with-resources和PreparedStatement是优越的。 try (Connection con = ...) { } 即使返回/异常,也会自动关闭连接。 try (PreparedSt ...
-
您需要在代码之上放置{$B-}语句,或在项目设置中启用布尔短路评估 。 由于{$B-}是默认值,因此您之前可能已将其打开,或者某个地方有一个{$B+}指令将其关闭。 在短路评估模式{$B-} ,Delphi创建(大致)等效于此的代码: if (L > 0) then begin if (S[i] > ' ') then begin if (S[L] > ' ') then begin ..... end; end; ...
-
如何避免重复代码?(how to avoid repeating code?)[2021-10-27]
你在这里做的是std::find()函数已经完成的,所以最好使用它(尽管你自己尝试实现这些东西当然可以)。 std::find()还演示了一种指示“未找到”条件的好方法 - 如果找不到该项,它将返回迭代器一个接一个的结尾。 这样,调用者可以通过比较返回的Data.end()迭代器来确定是否找到了匹配项。 What you're doing here is already done by the std::find() function, so it would be better to use that ( ... -
您可以通过非常通用的“实体”类型,特别是您利用各种魔术方法。 考虑这样的类(只是一些随机的便利方法,用于分享类似实体的类): properties as $p){ if (isset($data[$p])) $this->$p = $data[$p]; ...
-
这段代码的共同部分是获取列标识符并将它们转换为行加子集引用。 既然你想把这些计算值保留在对象上,就把它们设置在一个辅助函数中。 class Summary(object): def __init__(self,summary_df): self.summary = summary_df #look_up_table={dict created} def _update_for_columns(self, col1, col2): """Gi ...
-
避免代码重复(Avoid code repeat)[2024-02-08]
你可以将重复的代码移动到一个像这样的函数/子文件中: Set r = WordDoc.Range Do While UnifiedSearch (r, "name*author") If f Then If r.Start = fO Then Exit Do End If Else fO = r.Start f = True End If WordDoc.Range(r.Start + 4 ... -
如前所述,首先考虑您是否真的需要复制。 也许他们应该在一个共同的对象中传播。 也许他们不需要。 现在我们假设他们真的需要。 当然可以是这种情况。 PMD的复制粘贴检测器允许您在将其计为重复之前设置最小行数。 由于getter / setter每个只有三行(或两者都是6行),因此可以将阈值设置在那里。 As already noted, first consider whether you really need the duplication. Maybe they should be in a commo ...