编写我们的心界面和对应的Activity类
文件名填写newui。
编写此界面对应的Activity类
package org.snailteam;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class ManagerUI extends Activity {
private EditText message;
private Button showMessage;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newui);
message=(EditText)findViewById(R.id.message);
showMessage=(Button)findViewById(R.id.showmessage);
showMessage.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Bundle bundle = getIntent().getExtras();
String username = bundle.getString("key_username");
message.setText(username+"已经进入后台管理");
}
});
}
}
注册我们的Activity类(用向导添加),AndroidManifest.xml文件会显示
回到我们的主程序中
package org.snailteam;
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;
import android.widget.EditText;
import android.widget.TextView;
public class application extends Activity {
private EditText Username;
private Button buttonLogin;
private TextView title;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Username = (EditText) findViewById(R.id.username);
buttonLogin = (Button) findViewById(R.id.button_OK);
title = (TextView) findViewById(R.id.title);
buttonLogin.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
//========================================================
Intent open = new Intent();
Bundle bund = new Bundle();
bund.putString("key_username",Username.getText().toString());
open.putExtras(bund);
open.setClass(application.this,ManagerUI.class);//我们要传递给的Activity类
startActivity(open);
//===========================================================
}
});
}
}