Chinese, Traditional subtitles

← 12-28 Create an Object - Solution

Get Embed Code
13 Languages

Showing Revision 1 created 10/20/2015 by sp11.

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