Android基础知识学习——界面转换(完善)

MainActivity:

package com.example.xinwen;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
      private Button bt;
      private EditText st1,st2;
    @Override
   
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        bt=(Button)findViewById(R.id.denglu);
        st1=(EditText)findViewById(R.id.zhanghu);
        st2=(EditText)findViewById(R.id.mima);
       
    bt.setOnClickListener(new OnClickListener(){

  @Override
  
  
  public void onClick(View arg0) {
   // TODO Auto-generated method stub
   
   String usename=st1.getText().toString();
   String pwd=st2.getText().toString();
   if(usename.equals("zhangsan") && pwd.equals("zhangsan"))
   {
     Intent in=new Intent (MainActivity.this,FirstActivity.class);
     startActivity(in);
   }
    
  }

  private void elsif(boolean b) {
   // TODO Auto-generated method stub
   
  }});
 }


 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
   
}

 

FirstActivity:

package com.example.xinwen;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class FirstActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_first);
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.first, menu);
  return true;
 }

}


Android基础知识学习——界面转换(完善)_第1张图片Android基础知识学习——界面转换(完善)_第2张图片

你可能感兴趣的:(Android基础知识学习——界面转换(完善))