首页 \ 问答 \ 在Android对话框后创建另一个对话框(Creating another dialog after dialog Android)

在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
更新时间:2022-11-11 17:11

最满意答案

类名称如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.

相关问答

更多
  • 类名称如InvoiceReader,PriceCalculator,MessageBuilder,ArticleReader,InvoiceReader实际上并不是动词名称。 他们真的是“名词名词”的名字。 见代理名词 动词类的名字将类似于验证,操作,管理等。显然,这些更好地用作方法,并且作为类名称将是相当尴尬的。 “名词代理名词”类名称的最大问题在于它们对于该类什么是实际的(例如UserManager,DataProcessor等)可以给出很少的意义。 因此,他们更有可能blo肿,失去内在的凝聚力。 (见 ...
  • 你已经很准确地描述了情况。 -w在全局范围内启用警告(跨所有模块,除非它们特意将其关闭)。 use warnings表现为词法,不会影响其他模块中发生的情况。 话虽如此,我不认为这是一个更好的问题。 这真的是你想要的行为的问题。 我们不会说foreach比不知道断言的上下文更好。 如果您希望在全球范围内开启警告的行为,尽一切办法。 如果您想以不影响外部模块的方式打开警告,请执行此操作。 警告,在我看来,是一个开发和调试工具。 我试着总是用“on”(在我自己的代码中)的警告进行编程。 不管我是否将代码部署到启 ...
  • 为了使讨论更具体一点,并且由于评论中的空间有限,类似下面的内容会对您有用还是不适用? 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; ...
  • 你在这里做的是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 ...
  • 你可以将重复的代码移动到一个像这样的函数/子文件中: 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)