最近在开始接触Android APP开发,有了一点java基础以后,安卓代码确实看起来就没有那么难了,能够跟着书上把例程敲一遍,而后熟能生巧能够应用起来,如今写了一个简单的APP,实现的是Edit编辑框输入账号和密码,后台判断,若是正确则跳转到本CSDN博客网址,不然就经过Toast提示出错。java
案例以下,这个案例很好的把以前学过的相关空间和知识都联系起来,至关于复习了一遍:android
package com.example.button_first; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; //import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //登录账号 final EditText Tellphone = (EditText)findViewById(R.id.editText1); //登录密码 final EditText Cell = (EditText)findViewById(R.id.editText2); //要显示登录成功或失败的的文本 // final TextView show_Text = (TextView)findViewById(R.id.textView3); Button button = (Button)findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub String inputTellphone = Tellphone.getText().toString(); String cellTellphone = Cell.getText().toString(); if(inputTellphone.equals("morixinguan") && cellTellphone.equals("7387541")) { // show_Text.setText("登录成功!"); Toast.makeText(MainActivity.this, "登录成功!", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://blog.csdn.net/morixinguan")); startActivity(intent); } else { Toast.makeText(MainActivity.this, "登录失败!", Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "你的账号或密码有误!", Toast.LENGTH_SHORT).show(); } } }); } @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; } }
手机运行效果以下:app
本文同步分享在 博客“Engineer-Bruce_Yang”(CSDN)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。ide