惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
O
OpenAI News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News and Events Feed by Topic
S
Security Affairs
SecWiki News
SecWiki News
Project Zero
Project Zero
L
Lohrmann on Cybersecurity
P
Proofpoint News Feed
P
Palo Alto Networks Blog
L
LINUX DO - 最新话题
H
Hacker News: Front Page
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
The GitHub Blog
The GitHub Blog
I
InfoQ
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
B
Blog
IT之家
IT之家
AWS News Blog
AWS News Blog
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
Security Latest
Security Latest
美团技术团队
C
Check Point Blog
WordPress大学
WordPress大学
T
Tenable Blog
S
Security @ Cisco Blogs
Last Week in AI
Last Week in AI
博客园 - 聂微东
月光博客
月光博客
博客园 - 【当耐特】
S
Schneier on Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Secure Thoughts
Schneier on Security
Schneier on Security
C
Cisco Blogs
Cyberwarzone
Cyberwarzone

博客园 - looky

5个未来必不可少的IT技能 常用诺基亚S60手机软件应用 常用Android手机软件应用 常用iPhone手机 免费软件应用... Properties Table of Widgets: 简单 申请 msn.com邮箱 @ Android UI --- 设置ProgressBar的颜色 注册国际paypal支付 为何要划扣1美元 详析 Android Timer 更好方法 照相机捕获照片保存大小以及保存位置的问题 简单实现显示隐藏密码,在EditText中。 去掉标题栏和系统栏代码实现以及动态设置密码 Android里添加 Menu Android模拟器SD Card映像文件使用方法 Android的源代码结构 Android--输入法篇 Android Service Android开发中保存数据的四种方法方法 android 彻底关闭应用程序 返回键的捕获
纯代码实现 Android 登陆布局
looky · 2010-06-21 · via 博客园 - looky

        下面代码实现的是 登陆 ,一点XML 配置都没有.看起来显然没有之前的使用XML配置 例子清晰.
/**
 * 
 */
package com.birds.android.login;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
/**
 * @author birds
 * @date 2008-11-22
 * @file $
 */
public class LoginCodeUI extends Activity implements OnClickListener {
    private static final int BUTTON_ID_OK = 5000000;
    private static final int BUTTON_ID_CANCEL = 6000000;
    private static final int TEXT_ID_ONE = 111111;
    private static final int TEXT_PASSWD = 222222;
    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TableLayout tableLayout = new TableLayout(this);
        setContentView(tableLayout);
        TableRow row1 = new TableRow(this);
        tableLayout.addView(row1);
        TextView view1 = new TextView(this);
        view1.setText("账号名称:");
        view1.setWidth(100);
        EditText text1 = new EditText(this);
        text1.setWidth(150);
        text1.setSingleLine();
        text1.setFilters(new InputFilter[] { new InputFilter.LengthFilter(15) });
        text1.setId(TEXT_ID_ONE);
        row1.addView(view1);
        row1.addView(text1);
        TableRow row2 = new TableRow(this);
        tableLayout.addView(row2);
        TextView view2 = new TextView(this);
        view2.setWidth(100);
        view2.setText("账号密码:");
        EditText text2 = new EditText(this);
        text2.setSingleLine();
        text2.setWidth(150);
        // 设置为密码模式
        text2.setTransformationMethod(new PasswordTransformationMethod());
        // 设置最大长度,为15
        text2.setFilters(new InputFilter[] { new InputFilter.LengthFilter(15) });
        text2.setId(TEXT_PASSWD);
        row2.addView(view2);
        row2.addView(text2);
        TableRow row3 = new TableRow(this);
        tableLayout.addView(row3);
        Button b1 = new Button(this);
        b1.setText("确定");
        b1.setId(BUTTON_ID_OK);
        b1.setOnClickListener(this);
        Button b2 = new Button(this);
        b2.setText("取消");
        b2.setId(BUTTON_ID_CANCEL);
        b2.setOnClickListener(this);
        row3.addView(b1);
        row3.addView(b2);
    }
    @Override
    public void onClick(View v) {
        EditText t1 = (EditText) findViewById(TEXT_ID_ONE);
        EditText t2 = (EditText) findViewById(TEXT_PASSWD);
        if (v.getId() == BUTTON_ID_OK) {
            Builder alertDialog = new AlertDialog.Builder(this);
            alertDialog.setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface v, int btn) {
                            v.cancel();
                        }
                    });
            alertDialog.setTitle("输入的信息:" + t1.getText() + " 密码:"
                    + t2.getText());
            alertDialog.show();
        } else if (v.getId() == BUTTON_ID_CANCEL) {
            t1.setText("");
            t2.setText("");
        }
    }
}
   xml配置布局的灵活性明显,代码主要 是逻辑功能的实现, 有点 MVC 的思想 .
   xml为视图配置,逻辑代码另写class,android事件监听 为控制器.