Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android登录/注册示例项目_Android - Fatal编程技术网

Android登录/注册示例项目

Android登录/注册示例项目,android,Android,是否有一个在Android中实现登录/注册欢迎屏幕的参考示例项目 我曾想过,要做到这一点,我需要知道什么: 活动布局 文本字段验证 文本字段提示 启用/禁用UI元素(即,仅在输入数据时按login) 异步网络请求验证凭据 阻止等待登录的UI 根据登录结果转发到下一个活动 如果是第一次使用,请注册插曲 如果用户愿意,则取消网络登录(如果用户离开活动,请勿在回拨时崩溃) 保存用户数据、访问令牌(如果可用)或密码(并加密) 过渡动画,包括“拒绝访问”反馈 如果可用,请使用缓存凭据 登录“记住我”选择

是否有一个在Android中实现登录/注册欢迎屏幕的参考示例项目

我曾想过,要做到这一点,我需要知道什么:

  • 活动布局
  • 文本字段验证
  • 文本字段提示
  • 启用/禁用UI元素(即,仅在输入数据时按login)
  • 异步网络请求验证凭据
  • 阻止等待登录的UI
  • 根据登录结果转发到下一个活动
  • 如果是第一次使用,请注册插曲
  • 如果用户愿意,则取消网络登录(如果用户离开活动,请勿在回拨时崩溃)
  • 保存用户数据、访问令牌(如果可用)或密码(并加密)
  • 过渡动画,包括“拒绝访问”反馈
  • 如果可用,请使用缓存凭据
  • 登录“记住我”选择退出
  • 等等
还有很多要点要写,但你明白了

我怀疑,如果我错了,请纠正我,许多应用程序可能有(甚至开始于)登录/注册屏幕。可能有一个可定制的Eclipse项目在某个地方捕获了大多数最佳实践,这样开发人员就不需要重新发明轮子了

显然,许多应用程序都希望做不同的事情。显然,在某些情况下,上述情况毫无意义。但是可能对于某些应用程序来说,这是一个合理的“典型”登录活动?

1)在/res/layout中创建login.xml(活动布局)在本例中,还有一个更改密码的附加选项

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/username"
        android:hint="Username"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="180dp"
        android:layout_gravity="center"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/password"
        android:layout_width="250dp"
        android:hint="Password"
        android:layout_marginTop="20dp"
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/Loginbutton"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login" />

    <CheckedTextView
        android:id="@+id/changepassword"
        android:layout_width="wrap_content"
        android:layout_marginTop="75dp"
        android:clickable="true"
        android:layout_marginLeft="190dp"
        android:layout_height="wrap_content"
        android:text="Change_Login_Id" />

</LinearLayout>

最新版本的用于Eclipse的Android开发工具(ADT)插件有一个向导,可以创建一个新的LoginActivity,这是一个很好的起点。它有以下特点

  • 活动布局文本字段验证
  • 文本字段提示
  • 启用/禁用UI元素
  • 异步请求验证凭据
  • 阻止等待登录的UI
  • 取消登录
  • 等等

它位于文件->新建->其他->Android活动->LoginActivity

中,为什么这两个答案是不同的?一个就够了
public class Login extends Activity{
    private Button login;
    private EditText Username;
    private EditText Password;
    private CheckedTextView changeid;
    public SQLiteDatabase sampleDB;
    public String COLUMN_ID="_id";
    public String COLUMN1="username";
    public String COLUMN2="password";
    public String TABLE_NAME="Androdata";
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        login=(Button)findViewById(R.id.Loginbutton);
        Username=(EditText)findViewById(R.id.username);
        Password=(EditText)findViewById(R.id.password);
        changeid=(CheckedTextView)findViewById(R.id.changepassword);
        sampleDB =  this.openOrCreateDatabase(TABLE_NAME, MODE_PRIVATE, null);
        boolean x=init(TABLE_NAME);
        if(x==false)
        {
        createDB();
        insertDB();
        }
        changeid.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent myintent=new Intent("android.intent.action.DATABASE");
                startActivity(myintent);
            }
        });
        login.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int k=check();
                if(k==1)                
                {
                    Toast.makeText(Login.this, "Login Successful ...", Toast.LENGTH_SHORT).show();
                    Intent myintent=new Intent("android.intent.action.CHOICE");
                    startActivity(myintent);
                }
                else
                {
                    Username.setText("");
                    Password.setText("");
                    Toast.makeText(Login.this, "Authentication Failed...", Toast.LENGTH_SHORT).show();
                }   
            }
        });
    }
    public boolean init(String tableName)
    {
        Cursor cursor = sampleDB.rawQuery("select DISTINCT tbl_name from sqlite_master where tbl_name = '"+tableName+"'", null);
        if(cursor!=null) {
            if(cursor.getCount()>0) {
                                cursor.close();
                return true;
            }
                        cursor.close();
        }
        return false;
    }
    private void insertDB() {
        sampleDB.execSQL("INSERT INTO " +
                TABLE_NAME +
                " Values ('1','Androviewer','viewer');");   
        System.out.println("Inserted data successfully....");
    }
    private void createDB() {
        sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                TABLE_NAME+ "(" + COLUMN_ID
                + " integer primary key autoincrement, " + COLUMN1
                + " text not null,"+ COLUMN2
                + " text not null);");
        System.out.println("Database created successfully....");
    }
    private int check() {
        String a=Username.getText().toString();
        String b=Password.getText().toString();
        // TODO Auto-generated method stub
        Cursor c = sampleDB.rawQuery("SELECT username, password FROM " +
                TABLE_NAME +
                " where _id=1", null);

        if (c != null ) {
            if  (c.moveToFirst()) {
                do {
                    String orgusername = c.getString(c.getColumnIndex("username"));
                    String orgpassword = c.getString(c.getColumnIndex("password"));
                    if(a.equals(orgusername)&&b.equals(orgpassword))
                    {
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                }while (c.moveToNext());
            }
        }
        return 0;
    }
}
if u want a single time login u can use shared preferences or make a simple change in my db code .

1)u can set textfield hint in xml

android:hint="ur hint" 

2)Use Intent as i used to move forward from one activity to next.

Do u need any more