我到达最后一行时收到此错误.IndexOutOfBoundException无效索引20大小为20。
这是我的代码。
public class SocialListAdapter extends BaseAdapter {
private Activity activity;
private List<Item> items;
private List<Item> items2;
private List<Item> items3;
private List<FacebookItem> fb;
private List<Instagram> insta;
// private MainTable objBean;
private Item objBean;
private Item objBean2;
private Item objBean3;
// private MainTable objBean;
private int row;
private int i;
int layout1 = 0;
int layout2 = 1;
Session session;
String fbpostid;
private InstagramApp mApp;
private InstagramSession mSession;
private static final String API_URL = "https://api.instagram.com/v1";
String accessToken;
private DisplayImageOptions options;
ImageLoader imageLoader;
String name;
int fbcount;
int instacount;
public SocialListAdapter(Activity act, int resource, List<Item> arrayList,
List<Item> arrayList2, List<Item> arrayList3, String name,
int fbcount, int instacount) {
// super(act, resource, arrayList);
// TODO Auto-generated constructor stub
this.activity = act;
this.items = arrayList;
this.row = resource;
this.items2 = arrayList2;
this.items3 = arrayList3;
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getItemViewType(int position) {
objBean = items.get(position);
if (objBean.getI() == 0) {
return layout1;
} else if (objBean.getI() == 1) {
return layout2;
}
return i;
}
@Override
public int getCount() {
return items.size();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
objBean = items.get(position);
objBean2 = items2.get(position);
objBean3 = items3.get(position);
int type = getItemViewType(position);
i = objBean.getI();
// if(i == 0){
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// view = inflater.inflate(row, null);
if (type == layout1) {
view = inflater.inflate(R.layout.list, null);
} else if (type == layout2) {
view = inflater.inflate(R.layout.row1, null);
}
holder = new ViewHolder();
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
if ((items == null) || ((position + 1) > items.size()))
return view;
if ((items2 == null) || ((position + 1) > items2.size()))
return view;
if ((items3 == null) || ((position + 1) > items3.size()))
return view;
holder.tvinstatime = (TextView) view.findViewById(R.id.instatime);
holder.tvinstapostid = (TextView) view.findViewById(R.id.instapostid);
if (holder.tvinstapostid != null && null != objBean3.getinstapost_id()
&& objBean3.getinstapost_id().trim().length() > 0) {
holder.tvinstapostid.setText(Html.fromHtml(objBean3
.getinstapost_id()));
}
if (holder.tvinstatime != null && null != objBean3.getdatetime()
&& objBean3.getdatetime().trim().length() > 0) {
holder.tvinstatime.setText(Html.fromHtml(objBean3.getdatetime()));
}
holder.ivimage = (ImageView) view.findViewById(R.id.fbdp);
holder.buttonlike = (Button) view.findViewById(R.id.likelist);
if (holder.tvfbpostid != null && null != objBean.getfbpost_id()
&& objBean.getfbpost_id().trim().length() > 0) {
holder.tvfbpostid.setText(Html.fromHtml(objBean.getfbpost_id()));
}
return view;
}
这里我使用三个数组列表。
第一个是获得标志,并且取决于选择哪个布局,
第二个是获取fb的详细信息
第三个是获取instagram的数据。
我在这一行上收到错误
objBean2 = items2.get(position);
当我滚动到最后一个。