-
Title:
-
Description:
-
我們先做第一個
上面寫TextView=new TextView
-
then we pass context in as an input
parameter to the constructor.
然後通過內文輸入參數給建構者
-
The problem with this line of code is
that we're creating a new object but
這行編碼的問題是我們在建立新目標
-
we're not storing it
properly in a variable.
但沒有正確儲存在變數中
-
We're saying that the variable
should have data type TextView but
我們是說變數
應該有數據類型TextView
-
we forget to give it a variable name.
但忘了給變數名稱
-
So the correct code would
look something like this.
因此正確的編碼會像這樣
-
TextView followed by a variable name and
then equals new TextView.
變數名稱後面是TextView
然後等於新TextView
-
You can call the variable
name something else but
你可以稱變數名稱其他名稱
-
we just chose to use textView
with a lower case t.
但我們使用textview,t小寫
-
So in this case,
the error was missing variable name.
這個例子中
錯誤是遺漏參數名稱
-
Let's do the next one.
我們做下一個
-
It says, image view img = new ImageView.
上面寫image view img=new ImageView
-
The problem here is that this
is not a valid object data type.
這裡的問題是無有效的目標數據類型
-
Android defines a class called ImageView
with a capital I and a capital V and
安卓定義ImageView
I跟V大寫
-
it's squished together into one word.
並合成一個字
-
A valid class name can't
have any spaces in it.
有效的名稱不能有空格
-
The variable name looks okay, and
變數名稱看起來可以
-
then creating the new image
view looks okay as well.
建立新的影像檢視看起來也可以
-
So the only error was that it
had an incorrect class name.
因此錯誤是錯誤的等級名稱
-
In the third statement, we're trying
to create a new toggle button.
在第三行,我們要建立新的按鍵
-
It says ToggleButton button
= create ToggleButton.
上面寫ToggleButton button
= create ToggleButton.
-
We're calling the ToggleButton
class here, so
這邊我們稱為ToggleButton等級
-
we need to use the Java keyword new,
not create.
我們要用爪哇關鍵字新
不是建立
-
And this is the correct code.
這是正確的編碼
-
It says ToggleButton
button = new ToggleButton.
上面寫ToggleButton
button = new ToggleButton.
-
The problem here was not
using the Java keyword new.
這裡的問題是
沒有使用爪哇關鍵字新
-
New is the keyword that indicates that
we're trying to create a new object.
新是指建立新目標的關鍵字
-
In the fourth statement,
we're trying to create a new toast.
在第四行
我們要建立新的吐司
-
You could've Google searched for
how to create a new toast and
你可以谷哥搜尋
如何建立新吐司
-
then compared it with this code here.
然後與這裡的編碼比較
-
The problem here is that toast needs
to be spelled with a capital T,
這裡的問題是吐司的T要大寫
-
because this is a class name for Toast.
因為那是Toast的等級名稱
-
This is using a factory method
like we talked about earlier.
這是使用我們稍早說明的工廠法
-
This creates a new toast object and
then it gets stored in this variable.
建立新的吐司目標
然後儲存在變數裡
-
So the error here was just
an incorrect class name.
所以錯誤是不正確的等級名稱
-
So now that we know how to create
objects, how do we use these objects?
現在我們知道如何建立目標
我們要如何使用這些目標?