typedArray.getIndexCount()为什么返回总是0啊

lsdkzkald 2016-02-17 11:35:00
typedArray.getIndexCount()为什么返回总是0啊?

public class PlayActivity extends Activity {


private ListView play_listview;
private PlayAdapter pAdapter;


private List<ViewItem> list;


@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.play_activity);


play_listview = (ListView) findViewById(R.id.play_listview);
pAdapter = new PlayAdapter(this, getData());
play_listview.setAdapter(pAdapter);


}


//添加数据
public List<ViewItem> getData() {
list = new ArrayList<ViewItem>();
TypedArray typedArray = null;
typedArray = getResources().obtainTypedArray(R.array.pic_johanna); // pic_johanna是一组图片R资源的数组。

final int a = typedArray.getIndexCount(); //typedArray.getIndexCount()为什么返回总是0啊
int b = 10;
for (int i = 0; i < 20; i++) {
ViewItem item = new ViewItem();//这个必须在这里new 不然 数据都是一样的


if (i % 3 == 0) {
item.type = 0;
} else {
item.type = 1;
}

item.address = null;
item.name = "wang" + a;
list.add(item);

}


return list;
}
}

...全文
329 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lavor_zl 2016-05-02
  • 打赏
  • 举报
回复
你是不是在R.layout.play_activity对应的xml布局文件中, 添加了这样类似的命名空间xmlns:custom="http://schemas.android.com/apk/res/com.lavor.custom" 将它改为xmlns:app="http://schemas.android.com/apk/res-auto"就好了
lsdkzkald 2016-02-17
  • 打赏
  • 举报
回复
引用 1 楼 jklwan的回复:
打开obtainTypedArray的代码,你会看到这样一句array.mIndices[0] = 0;,然后getIndexCount()返回的是mIndices[0],那他就永远是0。不知道你是要用这个字段做什么?
我要数组里面的元素数量啊。
jklwan 2016-02-17
  • 打赏
  • 举报
回复
打开obtainTypedArray的代码,你会看到这样一句array.mIndices[0] = 0;,然后getIndexCount()返回的是mIndices[0],那他就永远是0。不知道你是要用这个字段做什么?

80,490

社区成员

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

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