自定义view中某条属性指向一个数组,怎么获取
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)