Beginner:What 我的代码的几部分是什么意思?

Beginner:What do several parts of my code mean?

因为我是一个绝对的初学者,所以我有一个非常简单的问题,但我无能为力 myself.Maybe 它们太简单了,因为我无法在论坛、书籍或其他互联网分页中找到答案。我不明白我的 java 代码的某些部分的含义,因为我只知道“'normal'”日食,而 android 与那个非常不同。

    import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Button;

import android.widget.Toast;

public class Spritkostenactivity extends Activity
implements View.OnClickListener{


    private TextView textcosts;
    private TextView textcostsperson;

    private Button buttonnew;
    private Button buttonstop;

这些元素(Button 和TextView)是对象、变量、属性吗?我该如何称呼他们?

        buttonnew= (Button)     findViewById(R.id.buttonerneuteberechnung);
        buttonnew.setOnClickListener(this);
        buttonstop= (Button) findViewById(R.id.buttonschliessen);
        buttonstop.setOnClickListener(this);

现在我将 xml 文件的元素放在 "buttons" 中。如果它们是对象,为什么我不必写像 "Button buttonnew=new ..." 这样的东西,因为在那之后按钮启动一个方法,所以它们需要是一个对象吗? "this" 是什么意思。我读到它表示实际对象,但实际对象是什么意思?

  Double.parseDouble(liters)

我的最后一个问题是关于方法 Double.parsedouble() 的。 你能告诉我 Double(.parsedouble) 代表什么吗?是启动方法的类名吗?

很抱歉一道题有好几题post,但我觉得这是基础知识,没必要在多题里post。 我希望你能帮助我。谢谢!

ButtonTextView 是 class 个名字。当我输入:

private Button myButton;

我创建了一个指向空地址位置的按钮类型对象的引用。

如果我再实例化一个对象如下:

myButton = new Button();

myButton 将引用程序内存中新创建的 Button 对象。

对于 android 或任何 Java Swing,Button 对象仅表示 GUI 界面中的按钮。虽然 TextView 是一个文本字段,显示.. 你猜对了.. text.


在你的例子中,Button 是你的 XML 文件中已有的描述你的 GUI 的东西,所以你使用 findViewById(..) 指向对象中的那个按钮。

关于this,它指的是你所在的class的一个对象。所以每当我实例化一个Spritkostenactivity类型的对象时,就会有一个按钮监听由于语句 buttonstop.setOnClickListener(this).

,单击 this 对象(Spritkostenactivity 的任何实例)

Double 是保存双精度浮点数的数据类型的 class 名称,parseDouble 是一个接受字符串并将其格式化为 double数.