为什么奇怪namimg的会展QUOT; AlertDialog.Builder"而不是" AlertDialogBu​​ilder" Android中会展、而不是、奇怪、

2023-09-05 06:04:29 作者:打小就酷

为什么不

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

而不是

  AlertDialog.Builder建设者=新AlertDialog.Builder(本);
builder.setTitle(富);
 
CES奇葩多 稀奇古怪产品大盘点

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

原因 解决方案

生成器是 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.