1. 效果图
文章来源地址https://www.toymoban.com/news/detail-513405.html
2.功能介绍:登录,注册,好友列表
3.核心代码
/**
* 登录页面
*/
public class LoginActivity extends BaseActivity {
private ActivityLoginBinding mBinding;
@Override
protected View getLayoutResId() {
mBinding = ActivityLoginBinding.inflate(getLayoutInflater());
return mBinding.getRoot();
}
@Override
protected void initListener() {
mBinding.register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(mContext, RegisterActivity.class));
}
});
mBinding.login.setOnClickListener(new View.OnClickListener() {
@Override
public 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>() {
@Override
public void done(User user, BmobException e) {
if (user != null) {
showToast("登录成功");
startActivity(new Intent(mContext, MainActivity.class));
} else {
showToast(e.getMessage());
}
}
});
}
}
});
}
@Override
protected void initData() {
}
}
/**
* 注册页面
*/
public class RegisterActivity extends BaseActivity {
private ActivityRegisterBinding mBinding;
@Override
protected View getLayoutResId() {
mBinding = ActivityRegisterBinding.inflate(getLayoutInflater());
return mBinding.getRoot();
}
@Override
protected void initListener() {
mBinding.register.setOnClickListener(new View.OnClickListener() {
@Override
public 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>() {
@Override
public void done(User user, BmobException e) {
if (user != null) {
showToast("注册成功");
finish();
} else {
showToast(e.getMessage());
}
}
});
}
}
});
}
@Override
protected void initData() {
}
}
/**
* 好友列表页面
*/
public class MainActivity extends BaseActivity {
private ActivityMainBinding mBinding;
@Override
protected View getLayoutResId() {
mBinding = ActivityMainBinding.inflate(getLayoutInflater());
return mBinding.getRoot();
}
@Override
protected void initListener() {
}
@Override
protected 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;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public 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;
}
}
}
文章来源:https://www.toymoban.com/news/detail-513405.html
到了这里,关于android仿QQ列表实现 android studio大作业,android studio课程设计的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!