自定义view中某条属性指向一个数组,怎么获取

u013361097 2016-05-18 11:54:51
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ScheduleView);
.........................................
int id = typedArray.getResourceId(R.styleable.ScheduleView_childDrawable,0);
typedArray.recycle();
TypedArray array = Resources.getSystem().obtainTypedArray(id);
int indexCount = array.getIndexCount();
if (indexCount>0){
backgrounds = new Drawable[indexCount];
for (int i = 0; i < indexCount; i++)
backgrounds[i] = array.getDrawable(array.getIndex(i));
}
..........................
array.recycle();
R.styleable.ScheduleView_childDrawable指向drawable数组资源
这样会报ArrayList的java.lang.UnsupportedOperationException的异常。。
at android.content.res.Resources_Delegate.obtainTypedArray(Resources_Delegate.java:491)
at android.content.res.Resources.obtainTypedArray(Resources.java:559)
at com.example.yzh.okhttp.view.ScheduleView.initSchedule(ScheduleView.java:55)

...全文
134 回复 打赏 收藏 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧