注意我编辑了 XML 文件!!!!
我有一个创建按钮的 Activity,当您单击该按钮时,它会调用另一个 Activity,但是当我运行该应用程序时,它只显示一个空白页面。活动:
package com.elichai.tfillin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
public void OnCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
private void displayCamera() {
Intent i = new Intent(this, CameraActivity.class);
startActivityForResult(i, 0);
}
public void addListenerOnButton() {
final Button button1 = (Button) findViewById(R.id.button1);
//Button button2 = (Button) findViewById(R.id.button2);
//Button button3 = (Button) findViewById(R.id.button3);
//Button button4 = (Button) findViewById(R.id.button4);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
displayCamera();
//finish();
}
});
}
}
这是activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="7dp"
android:text="@string/button" />
<Button
android:id="@+id/button2"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="182dp"
android:text="@string/button" />
<Button
android:id="@+id/button3"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="260dp"
android:text="@string/button" />
<Button
android:id="@+id/button4"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="182dp"
android:layout_marginTop="260dp"
android:text="@string/button" />
<TextView
android:id="@+id/textView1"
android:layout_width="223dp"
android:layout_height="52dp"
android:layout_marginLeft="85dp"
android:layout_marginTop="215dp"
android:text="@string/switch_cam"
android:textSize="30sp" />
</LinearLayout>
谢谢!