谁能告诉我这题代码都没错为什么点击button没有显示任何输出system.out。println()的内容
string。xml的:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">demon1</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="button_name">登录</string>
</resources>
activity_main.xml:
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/imageView1"
android:layout_marginTop="48dp"
android:text="@string/button_name" />
mainactivity.java里的相关代码:
package com.example.demon1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button Loginbutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Loginbutton=(Button) findViewById(R.id.button1);
Loginbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
System.out.println("button已被点击!");
}
});
}