【发布时间】:2015-09-16 17:45:32
【问题描述】:
我已经做了很长时间了,但仍然无法弄清楚如何从我的字符串中删除“id”。 它使用相同的方法添加到数组列表中,但不会从字符串中删除。 怎么去掉?
travelselectedId.remove(tv.getId());
还请解释一下为什么会抛出这个 IndexOutOfBoundIndex 错误。我知道这与我的 getId() 方法有关,但无法找出确切原因。
for(int i=1;i<=activityList.size();i++)
{
final TextView tv=new TextView(this);
tv.setId(Integer.parseInt(activityList.get(i-1).get(Table.user_travelactivities.id.toString())));
tv.setText(activityList.get(i-1).get(Table.user_travelactivities.travelactivity.toString()));
if(!travelselectedId.contains(tv.getId()))
{
tv.setBackgroundResource(R.drawable.round_rect_shape);
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.plus_profile,0, 0, 0);
tv.setTextColor(this.getResources().getColor(R.color.tripoto_orange));
}
else
{
tv.setBackgroundResource(R.drawable.round_filled_rect_shape);
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check,0,0,0);
tv.setTextColor(NewProfileSettings.this.getResources().getColor(R.color.white));
}
tv.setCompoundDrawablePadding(10);
tv.setTextSize(16f);
FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.horizontal_spacing=14;
params.vertical_spacing=14;
x1.addView(tv,params);
tv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (travelselectedId.contains(tv.getId())) {
tv.setBackgroundResource(R.drawable.round_rect_shape);
tv.setTextColor(NewProfileSettings.this.getResources().getColor(R.color.tripoto_orange));
travelselectedId.remove(tv.getId());// ================= THIS LINE WHAT SHOULD I DO
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.plus_profile,0, 0, 0);
}
else
{
tv.setBackgroundResource(R.drawable.round_filled_rect_shape);
tv.setTextColor(NewProfileSettings.this.getResources().getColor(R.color.white));
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check,0,0,0);
travelselectedId.add(tv.getId());
}
}
});
}
}
【问题讨论】:
-
int i=1不用多看,你可能想要int i=0。或者更大胆的i<=activityList.size()+1; -
那无济于事。我已经编辑了问题。
-
试试
travelselectedId.remove(v.getId());
标签: android arraylist indexoutofboundsexception