安卓開發:簡單的登錄跳轉_APK實現直接跳轉到本CSDN博客

最近在開始接觸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

相關文章
相關標籤/搜索