1.java.net.SocketException: socket failed: EPERM (Operation not permitted)
出现原因:一开始网络请求时我没有赋予网络权限,我重新给程序赋予权限时我并没有卸载程序,只是重新编译,系统并没有获取到配置文件中的权限,因此需要卸载重新安装
2.recycrview包含edittext,滑动错乱问题?
在onBindViewHolder中这样设置TextWatcher
//1移除监听
if(holder.stuAge.tag is TextWatcher) {
holder.stuAge.removeTextChangedListener(holder.stuAge.tag as TextWatcher)
}
//2设置内容
holder.stuAge.setText(student.age)
val watch = object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
student.age = p0.toString()
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
}
//3设置监听
holder.stuAge.addTextChangedListener(watch)
//4设置tag
holder.stuAge.tag = watch
3.RecyclerView添加分割线?
a.添加默认分割线,即安卓自带的分割线
//添加Android自带的分割线
recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
b.自定义分割线
打开DividerItemDecoration的源码
public void setDrawable(@NonNull Drawable drawable) {
if (drawable == null) {
throw new IllegalArgumentException("Drawable cannot be null.");
}
mDivider = drawable;
}
我们只需调用这个方法,然后传入一个Drawable对象就可以完成自定义,现在用shape来编写一个分割线样式
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/purple_200"
android:centerColor="@color/teal_200"
android:endColor="@color/design_default_color_primary"
android:type="linear"/>
<size android:height="3dp"/>
</shape>
添加代码改成如下
//添加自定义分割线
DividerItemDecoration divider = new DividerItemDecoration(this,DividerItemDecoration.VERTICAL);
divider.setDrawable(ContextCompat.getDrawable(this,R.drawable.custom_divider));
recyclerView.addItemDecoration(divider);
4.json转实体类的在线网站
https://www.bejson.com/json2javapojo/new/
http://www.jsons.cn/json2java/
http://tool.chinaz.com/Tools/json2entity.aspx
5.安卓对象传递错误
Android中的Activity传递数据时,为了方便往往将很多数据封装成对象,然后将整个对象传递过去。传对象的时候有两种情况,一种是实现Parcelable接口,一种是实现Serializable接口。
可以用bundle putSerializable(Key,Object)传递数据或者直接用intent putExtrr(Key,Object)传递数据。
今天我在进行传递数据的时候遇到了问题。
1、抛出java.io.NotSerializableException异常
抛出这个异常是因为你的对象没有实现Serializable接口,只要实现该接口就好了。
2、抛出java.lang.RuntimeException异常
抛出这个异常是因为传递的对象里面的对象也要实现Serializable接口。

最低0.47元/天 解锁文章
3万+





