有人可以帮我试试 onclick android 教程如何使用按钮更改页面,但我卡住了我收到一个错误,提示字段 Main.Activity.b1 的值未使用我无法弄清楚
package com.example.lasttry;
package com.example.lasttry;
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;
import android.widget.EditText;
import android.content.Intent;
public class MainActivity extends Activity implements OnClickListener {
private Button b1;
public final static String EXTRA_MESSAGE = "com.example.lasttry";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setContentView(R.layout.activity_main);
this.b1 = (Button)this.findViewById(R.id.b1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v) {
finish(); // TODO Auto-generated method stub
}
public void sendMessage(View v){
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText= (EditText) findViewById(R.id.b1);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}