這是我第一次嘗試創建一個android應用程序,所以我一直在犯很多惱人的初學者錯誤!現在我只是想創建一個非常簡單的登錄/註冊系統。但是,我似乎誤解了如何處理用戶輸入的輸入。 從以前的文章中我已經看到了這裏,我試圖做這樣的事情:Android SDK:findViewById(int)未定義類型
//in Register class
public void submission(View view){
//Call User Constructor based on info received from Registration Activity
EditText enteredUser = (EditText)findViewbyId(R.id.enteredUser);
//then use the input from this field to do other stuff
}
但是出於某種原因,我不斷收到錯誤findViewById(INT)是未定義的類型註冊(我目前所在班級的名字)。有人能告訴我我做錯了什麼嗎?我很確定我在頂部有正確的導入語句(android.widget.EditText)。
這裏是相應的XML代碼:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Register" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter New UserName:" />
<EditText
android:id="@+id/enteredUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:ems="10" >
<requestFocus />
</EditText>
...more input buttons etc...
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/confirmPass"
android:layout_alignParentBottom="true"
android:layout_marginBottom="64dp"
android:onClick = "submission" <----- Used to call the submission function after
android:text="Submit" /> all inputs have been filled
</RelativeLayout>
對不起,我有點長篇大論的問題,但我將不勝感激任何幫助。
謝謝!
是的,即公共類Register擴展Activity {}(它包含我定義的java函數) – 2013-03-11 00:24:48
嘗試清理你的項目。我也很好奇,這是IDE唯一說你有錯誤的東西嗎?或任何Android相關@HoanNguyen這是一個編譯時錯誤,findViewById()是Activity的一部分。 – 2013-03-11 00:26:32
不,我一直關注的教程沒有說明我是否應該這樣做。我在哪裏打電話給這個? – 2013-03-11 00:27:59