1. 项目功能思维导图
2. 项目涉及到的技术点
- 使用SQLite数据库实现数据存储
- 使用CountDownTimer实现启动页倒计时
- 使用SharedPreferences实现记住密码登录
- 使用BottomNavigationView实现底部导航栏
- 使用Activity+Fragment实现底部导航栏页面之间切换
- 使用RecyclerView+adapter实现商品列表
- 使用CardView卡片控件实现头像圆角
- 使用AlertDialog自定义布局来实现收货地址
3. 项目截图
4. 项目部分功能代码实现
- 底部导航栏实现
public class MainActivity extends AppCompatActivity {private HomeFragment mHomeFragment;private CarFragment mCarFragment;private OrderFragment mOrderFragment;private MineFragment mMineFragment;private BottomNavigationView mBottomNavigationView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//初始化控件mBottomNavigationView = findViewById(R.id.bottomNavigationView);//mBottomNavigationView设置点击事件mBottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {@Overridepublic boolean onNavigationItemSelected(@NonNull MenuItem item) {if (item.getItemId() == R.id.home) {selectedFragment(0);} else if (item.getItemId() == R.id.car) {selectedFragment(1);} else if (item.getItemId() == R.id.order) {selectedFragment(2);} else {selectedFragment(3);}return true;}});//默认首页选中selectedFragment(0);}private void selectedFragment(int position) {FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();hideFragment(fragmentTransaction);if (position == 0) {if (mHomeFragment == null) {mHomeFragment = new HomeFragment();fragmentTransaction.add(R.id.content, mHomeFragment);} else {fragmentTransaction.show(mHomeFragment);}} else if (position == 1) {if (mCarFragment == null) {mCarFragment = new CarFragment();fragmentTransaction.add(R.id.content, mCarFragment);} else {fragmentTransaction.show(mCarFragment);mCarFragment.loadData();}} else if (position == 2) {if (mOrderFragment == null) {mOrderFragment = new OrderFragment();fragmentTransaction.add(R.id.content, mOrderFragment);} else {fragmentTransaction.show(mOrderFragment);mOrderFragment.loadData();}} else {if (mMineFragment == null) {mMineFragment = new MineFragment();fragmentTransaction.add(R.id.content, mMineFragment);} else {fragmentTransaction.show(mMineFragment);}}//一定要提交fragmentTransaction.commit();}private void hideFragment(FragmentTransaction fragmentTransaction) {if (mHomeFragment != null) {fragmentTransaction.hide(mHomeFragment);}if (mCarFragment != null) {fragmentTransaction.hide(mCarFragment);}if (mOrderFragment != null) {fragmentTransaction.hide(mOrderFragment);}if (mMineFragment != null) {fragmentTransaction.hide(mMineFragment);}}
}
- 修改密码
public class UpdatePwdActivity extends AppCompatActivity {private EditText et_new_password;private EditText et_confirm_password;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_update_pwd);//初始化控件et_new_password =findViewById(R.id.et_new_password);et_confirm_password =findViewById(R.id.et_confirm_password);//修改密码点击事件findViewById(R.id.btn_update_pwd).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String new_pwd =et_new_password.getText().toString();String confirm_pwd =et_confirm_password.getText().toString();if (TextUtils.isEmpty(new_pwd) || TextUtils.isEmpty(confirm_pwd)){Toast.makeText(UpdatePwdActivity.this, "信息不能为空", Toast.LENGTH_SHORT).show();}else if(!new_pwd.equals(confirm_pwd)){Toast.makeText(UpdatePwdActivity.this, "新密码和确认密码不一致", Toast.LENGTH_SHORT).show();}else {UserInfo userInfo = UserInfo.getUserInfo();if (null!=userInfo){int row = UserDbHelper.getInstance(UpdatePwdActivity.this).updatePwd(userInfo.getUsername(), new_pwd);if (row>0){Toast.makeText(UpdatePwdActivity.this, "密码修改成功,请重新登录", Toast.LENGTH_SHORT).show();//回传的时候要用 startActivityForResult启动一个页面,并且在该页面要设置setResultsetResult(1000);finish();}else {Toast.makeText(UpdatePwdActivity.this, "修改失败", Toast.LENGTH_SHORT).show();}}}}});//返回findViewById(R.id.toolbar).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {finish();}});}
}
- 商品详情
public class ProductDetailsActivity extends AppCompatActivity {private ImageView product_img;private TextView product_title;private TextView product_price;private TextView product_details;private ProductInfo productInfo;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_product_details);//获取传递的数据productInfo = (ProductInfo) getIntent().getSerializableExtra("productInfo");//返回findViewById(R.id.toolbar).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {finish();}});//初始化控件product_img = findViewById(R.id.product_img);product_title = findViewById(R.id.product_title);product_price = findViewById(R.id.product_price);product_details = findViewById(R.id.product_details);//设置数据if (null != productInfo) {product_img.setImageResource(productInfo.getProduct_img());product_title.setText(productInfo.getProduct_title());product_details.setText(productInfo.getProduct_details());product_price.setText(productInfo.getProduct_price() + "");}//加入购物车findViewById(R.id.addCar).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {new AlertDialog.Builder(ProductDetailsActivity.this).setTitle("确认是否加入到购物车?").setPositiveButton("确认", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {UserInfo userInfo = UserInfo.getUserInfo();if (userInfo != null) {//加入到购物车int row = CarDbHelper.getInstance(ProductDetailsActivity.this).addCar(userInfo.getUsername(), productInfo.getProduct_id(), productInfo.getProduct_img(), productInfo.getProduct_title(), productInfo.getProduct_price());if (row > 0) {Toast.makeText(ProductDetailsActivity.this, "添加成功", Toast.LENGTH_SHORT).show();finish();} else {Toast.makeText(ProductDetailsActivity.this, "添加失败", Toast.LENGTH_SHORT).show();}}}}).setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {}}).show();}});}
}