为什么奇怪namimg的会展QUOT; AlertDialog.Builder"而不是" AlertDialogBu​​ilder" Android中 [英] Why strange namimg convention of "AlertDialog.Builder" instead of "AlertDialogBuilder" in Android

查看:104
本文介绍了为什么奇怪namimg的会展QUOT; AlertDialog.Builder"而不是" AlertDialogBu​​ilder" Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不

  AlertDialogBu​​ilder建设者=新AlertDialogBu​​ilder(本);
builder.setTitle(富);
 

而不是

  AlertDialog.Builder建设者=新AlertDialog.Builder(本);
builder.setTitle(富);
 

更新:我想知道背后的这种写作/组织的

原因
解决方案

生成器 AlertDialog 类中的静态内部类。因此,要创建一个生成器类对象,你需要调用 AlertDialog.Builder

由于没有课例如 AlertDialogBu​​ilder ,所以你不能这样做。

如果你愿意,你也可以像波纹管使用。

 生成器生成器=新生成器(本);
builder.setTitle(富);
 

但使用这样的,你需要导入的生成器类类像

 进口android.app.AlertDialog.Builder;
 

而不是仅仅

 进口android.app.AlertDialog;
 

一个简单的例子

  A级{
     静态类B {}
}
 

您无法使用

  AB OBJ =新的AB();
 

您必须使用

  A·B的obj =新A·B();
 

希望你现在清楚了。

Why not

AlertDialogBuilder builder = new  AlertDialogBuilder(this);
builder.setTitle("foo");

instead of

AlertDialog.Builder builder = new  AlertDialog.Builder(this);
builder.setTitle("foo");

Update: I want to know the reason behind this kind of writing/organization

解决方案

Builder is the static inner class inside the AlertDialog class. So to create a Builder class object, you need to call AlertDialog.Builder.

As there is no class like AlertDialogBuilder so you cannot do that.

If you want you can also use as like bellow.

Builder builder = new Builder(this);
builder.setTitle("foo");

But to use like this you need to import the Builder class to your class like

import android.app.AlertDialog.Builder;

instead of just

import android.app.AlertDialog;

A simple example

class A{
     static class B{}
}

you cannot use

AB obj = new AB();

you have to use

A.B obj = new A.B();

Hope you are clear now.

这篇关于为什么奇怪namimg的会展QUOT; AlertDialog.Builder"而不是" AlertDialogBu​​ilder" Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆