【发布时间】:2014-12-01 00:13:10
【问题描述】:
将 indexOf 与可绘制资源列表一起使用时遇到问题。我的索引 i 给我的值为 -1(它没有找到可绘制资源)。
Booster booster = new Booster();
Booster booster1 = booster.findBooster(R.drawable.booster_empty);
public Booster findBooster(int boosterID) {
int[] boosterIDs = new int [] {
R.drawable.booster_empty,
R.drawable.booster_posts_1,
};
String[] names = new String[] {
"blah",
"blah"
};
String[] descriptions = new String[] {
"blah",
"blah"
};
String[] boosts = new String[] {
"blah",
"blah"
};
int i = Arrays.asList(boosterIDs).indexOf(boosterID);
Booster booster = new Booster(boosterID, names[i], descriptions[i], boosts[i]);
return booster;
}
我知道这可能是我缺少的一些非常简单的东西。请帮忙!
【问题讨论】:
标签: java android list drawable indexof