项目简介:基于Android手机的一款团购类型的软件
1. 用户登录注册功能
通过用户输入的用户名和密码判断是否注册,或者用户名密码是否正确,从SharePreferences 里面的数据经行判断
2. 主界面展示
因为是团购类型的app,所以主要是界面的展示,因此使用了大量
的控件,例如tab的切换,ViewPager的左右滑动
3. 搜索功能
根据用户输入的关键字,匹配相关信息,然后显示到界面
责任描述:主要负责界面的显示
这里界面使用的是ViewPager,ListView等的嵌套,不做多加描述,我认为技术难点在登录界面的逻辑判断
package com.scxh.android.sqllite;
import com.scxh.android.Bean.User;
import com.scxh.android.preference.SharedPreferencesHelper;
import com.scxh.android.ui.test.MeiTuanActivity;
import com.scxh.myproject.R;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class LoginDataSavaDB extends Activity {
private Button mButton;
private TextView mTextView;
private EditText mUserName, mPassWord;
private SQLiteDatabase db;
private CheckBox mCheckBox;
private SharedPreferencesHelper mSharedPreferencesHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_register);
DataBaseHelper dataBaseHelper = DataBaseHelper
.getInstanceOfDataBaseHelper(this);
db = dataBaseHelper.getReadableDatabase();
mTextView = (TextView) findViewById(R.id.meituan_register_mianfeizhuce);
mButton = (Button) findViewById(R.id.meituan_register_btn);
mUserName = (EditText) findViewById(R.id.meituan_register_user);
mPassWord = (EditText) findViewById(R.id.meituan_register_password);
mCheckBox = (CheckBox) findViewById(R.id.remenber_password);
mSharedPreferencesHelper = SharedPreferencesHelper
.getInstancePreferencesHelper(this);
User user = mSharedPreferencesHelper.getUserFromPreferences();
if (user.getCheckbox()) {
mUserName.setText(user.getName());
mPassWord.setText(user.getPassWord());
mCheckBox.setChecked(true);
}
mTextView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(LoginDataSavaDB.this,
RegisterDataSavaDB.class);
startActivity(intent);
}
});
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String username = mUserName.getText().toString();
String password = mPassWord.getText().toString();
if (username.equals("") || password.equals("")) {
Toast.makeText(LoginDataSavaDB.this, "用户名或密码不能为空",
Toast.LENGTH_SHORT).show();
} else {
Cursor cursor = db.query("user", new String[] { "username",
"password" }, "username = ? and password=?",
new String[] { username, password }, null, null,
null, null);
if (cursor.getCount() == 0) {
Toast.makeText(LoginDataSavaDB.this, "用户名或密码输入错误",
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(LoginDataSavaDB.this,
MeiTuanActivity.class));
}
}
if (mCheckBox.isChecked()) {
User user = new User();
user.setName(username);
user.setPassWord(password);
user.setCheckbox(true);
mSharedPreferencesHelper.saveUserToPreferences(user);
} else {
User user = new User();
user.setName(username);
user.setPassWord(password);
user.setCheckbox(false);
mSharedPreferencesHelper.saveUserToPreferences(user);
}
}
});
}
}