1. 效果图
2.功能介绍:登录,注册,好友列表
3.核心代码
/*** 登录页面*/public class LoginActivity extends BaseActivity {private ActivityLoginBinding mBinding;@Overrideprotected View getLayoutResId() {mBinding = ActivityLoginBinding.inflate(getLayoutInflater());return mBinding.getRoot();}@Overrideprotected void initListener() {mBinding.register.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {startActivity(new Intent(mContext, RegisterActivity.class));}});mBinding.login.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {String username = mBinding.username.getText().toString();String password = mBinding.password.getText().toString();if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {showToast("请完善信息");} else {User user = new User();user.setUsername(username);user.setPassword(password);user.login(new SaveListener<User>() {@Overridepublic void done(User user, BmobException e) {if (user != null) {showToast("登录成功");startActivity(new Intent(mContext, MainActivity.class));} else {showToast(e.getMessage());}}});}}});}@Overrideprotected void initData() {}}
/*** 注册页面*/public class RegisterActivity extends BaseActivity {private ActivityRegisterBinding mBinding;@Overrideprotected View getLayoutResId() {mBinding = ActivityRegisterBinding.inflate(getLayoutInflater());return mBinding.getRoot();}@Overrideprotected void initListener() {mBinding.register.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {String username = mBinding.username.getText().toString();String password = mBinding.password.getText().toString();if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {showToast("请完善信息");} else {User user = new User();user.setUsername(username);user.setPassword(password);user.signUp(new SaveListener<User>() {@Overridepublic void done(User user, BmobException e) {if (user != null) {showToast("注册成功");finish();} else {showToast(e.getMessage());}}});}}});}@Overrideprotected void initData() {}}
/*** 好友列表页面*/public class MainActivity extends BaseActivity {private ActivityMainBinding mBinding;@Overrideprotected View getLayoutResId() {mBinding = ActivityMainBinding.inflate(getLayoutInflater());return mBinding.getRoot();}@Overrideprotected void initListener() {}@Overrideprotected void initData() {mBinding.listview.setAdapter(new MyAdapter(this, ContactInfo.getContactInfoList()));}public static class MyAdapter extends BaseAdapter {private List<ContactInfo> list;private Context mContext;public MyAdapter(Context context, List<ContactInfo> contactInfos) {this.list = contactInfos;this.mContext = context;}@Overridepublic int getCount() {return list.size();}@Overridepublic Object getItem(int i) {return list.get(i);}@Overridepublic long getItemId(int i) {return i;}@Overridepublic View getView(int i, View view, ViewGroup viewGroup) {View rootView = LayoutInflater.from(mContext).inflate(R.layout.list_item, null);TextView username = rootView.findViewById(R.id.username);TextView content = rootView.findViewById(R.id.content);username.setText(list.get(i).getUsername());content.setText(list.get(i).getContent());return rootView;}}}