标签:
登录java
package com.hanqi.textapp1; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity { String code; String name; String pass; EditText denglu; EditText mima; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } //View 代表事件的发起者 // 注册 public void bt1_onclick(View v){ //带返回的打开注册的 Activity //返回注册信息 //1.准备带返回的意图 Intent intent=new Intent(this,zhuceActivity.class); startActivityForResult(intent, 1); } //处理返回信息 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //处理返回信息 //判断请求码 if(requestCode==1){ //判断结果码 if(resultCode==RESULT_OK){ //接受返回的信息 code= data.getStringExtra("usercode"); name= data.getStringExtra("username"); pass= data.getStringExtra("password"); } if(requestCode==RESULT_CANCELED){ } } } //登陆 public void bt2_onclick(View v){ //判断 //1取得填写信息 denglu=(EditText)findViewById(R.id.et_usercode); mima =(EditText)findViewById(R.id.et_password); String dl=denglu.getText().toString(); String mm=mima.getText().toString(); //2 是否正确填写 if(dl.trim().length()==0||mm.trim().length()==0){ Toast.makeText(MainActivity.this, "用户代码或密码为空", Toast.LENGTH_LONG).show(); return; } //3判断有无注册信息 //1)没找到注册信息 //2)填写的用户信息未注册 if(code==null||!code.equals(dl)){ Toast.makeText(MainActivity.this, "用户尚未注册", Toast.LENGTH_SHORT).show(); return; } //4判断注册信息是否匹配 if(!pass.equals(mm)){ Toast.makeText(MainActivity.this, "密码错误", Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(MainActivity.this, "用户验证成功", Toast.LENGTH_SHORT).show(); Intent intent=new Intent(this,textActivity.class); intent.putExtra("nicheng",name); startActivity(intent); finish(); } } }
注册java
package com.hanqi.textapp1; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; import android.widget.Toast; public class zhuceActivity extends AppCompatActivity { EditText et_usercode1; EditText et_password1; EditText et_username1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zhuce); et_usercode1=(EditText)findViewById(R.id.et_usercode1); et_password1=(EditText)findViewById(R.id.et_password1); et_username1=(EditText)findViewById(R.id.et_username); } public void bt2_onclick(View v){ //返回注册信息 //用户代码取得 String usercoud=et_usercode1.getText().toString(); if(usercoud==null||usercoud.trim().length()==0){ Toast.makeText(zhuceActivity.this, "请正确填写用户代码", Toast.LENGTH_SHORT).show(); return; } String username=et_username1.getText().toString(); if(usercoud==null||usercoud.trim().length()==0){ Toast.makeText(zhuceActivity.this, "请正确填写用户名称", Toast.LENGTH_SHORT).show(); return; } String password=et_password1.getText().toString(); if(usercoud==null||usercoud.trim().length()==0){ Toast.makeText(zhuceActivity.this, "请正确填写用户密码", Toast.LENGTH_SHORT).show(); return; } Intent intent=new Intent(); intent.putExtra("usercode",usercoud); intent.putExtra("username",username); intent.putExtra("password",password); //设置返回信息,1 结果码 2 携带数据的intent setResult(RESULT_OK,intent); finish(); } public void bt1_onclick(){ setResult(RESULT_CANCELED,null); finish(); } }
显示java
package com.hanqi.textapp1; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class textActivity extends Activity { EditText dh; TextView nc; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.textactivity); dh=(EditText)findViewById(R.id.dianhua); Intent intent=getIntent(); String str =intent.getStringExtra("nicheng").toString(); nc=(TextView)findViewById(R.id.wenben); nc.setText(str); } //检查和获取电话号码的方法 public String getphone(){ String phone=dh.getText().toString().trim(); //验证 if(phone.length()==0){ Toast.makeText(textActivity.this, "正确输入号码", Toast.LENGTH_SHORT).show(); return null; } else { return phone; } } public void dadianhua(View v){ //得到电话号码 String phone=getphone(); if(phone==null){ return; } //调用打电话界面,隐式意图 Intent intent=new Intent(Intent.ACTION_DIAL);//调用打电话的界面 //传送电话号码 tel:number Uri uri=Uri.parse("tel:"+phone); intent.setData(uri); startActivity(intent); } public void dadianhua2(View v){ String phone=getphone(); if(phone==null){ return; } //调用直接拨打需要授权 Intent intent=new Intent(Intent.ACTION_CALL);//调用打电话的界面 //传送电话号码 tel:number Uri uri=Uri.parse("tel:"+phone); intent.setData(uri); //处理异常 try { startActivity(intent); } catch (Exception e){ e.printStackTrace();//打印异常 } } }
标签:
原文地址:http://www.cnblogs.com/storm47/p/5533585.html