我正在为安卓开发一个应用程序。主屏幕有 6 个按钮。每个按钮通向另一个屏幕。我在使用使按钮在单击时执行任何操作的代码时遇到问题。这就是我所拥有的:在主页上,我的按钮 ID 是 glass 单击时打开的页面是 glass.xml
android:onClick="Intent i = new Intent(FirstActivity.this, SecondActivity.class);"
和我的 scr 文件夹我有 java 活动 FirstActivity.java
package install.fineline;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class FirstActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fine_line);
Button btnload = (Button) findViewById(R.id.glass);
btnload.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(this, SecondActivity.class);
startActivity(i);
}
}
和 SecondActivity.java
package install.fineline;
import android.app.Activity;
import android.os.Bundle;
public class SecondActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.glass);
}
}
我究竟做错了什么?