我今天安裝了Android的SDK包和我下面的「我的第一個應用程序」教程中,我被卡住,它指出:響應發送按鈕
打開MainActivity類別(位於項目的src /目錄下)並添加相應的方法:
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
}
我在哪裏把這個文件?這是「MainActivity.java」文件嗎?
我試過了,我不斷收到錯誤,所以我顯然在某處出錯了。
activity_main.xml中:
<LinearLayout 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:orientation="horizontal">
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
MainActivity.java:
package com.example.myfirstapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
希望我已經作出了明確的問題,我看了論壇上的一個答案,但我不能」找不到任何東西。
錯誤是什麼? ..你可以發佈完整的活動代碼? – Shubhank