[教学] Android PinnedSectionListView ArrayIndexOutOfBoundsException
超简单教学Tutorial extends BaseAdapter implements PinnedSectionListAdapterjava.lang.ArrayIndexOutOfBoundsException
at android.widget.AbsListView$RecycleBin.addScrapView
1. Does your adapter handle at least two types of views in getViewTypeCount() method: items and sections?
Remember add in getItemViewType getViewTypeCount 记得添加 getItemViewType getViewTypeCount
2. java.lang.ArrayIndexOutOfBoundsException at android.widget.AbsListView$RecycleBin.addScrapView
getItemViewType return either 0 or 1,只能return 0 或 1
public class NewsListAdapter extends BaseAdapter implements PinnedSectionListAdapter{
private static final int[] COLORS = new int[] {
android.R.color.holo_purple, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_blue_light,
android.R.color.holo_purple, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_blue_light,
android.R.color.holo_purple, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_blue_light,
android.R.color.holo_purple, android.R.color.holo_green_light,
android.R.color.holo_orange_light, android.R.color.holo_blue_light};
public NewsListAdapter(Context c) {
//mContext = c;
}
public int getCount() {
return oNewsItems.size();
}
public NewsItem getItem(int position) {
return oNewsItems.get(position);
}
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(oNews.id.equals("0"))
{
TextView txtTitle = (TextView)view.findViewById(R.id.txtTitle);
TextView.setBackgroundResource(COLORS);
return view;
}
@Override
public boolean isItemViewTypePinned(int viewType) {
// TODO Auto-generated method stub
return viewType == 0;
}
@Override
public int getItemViewType(int position) {
if(Integer.parseInt(getItem(position).id) == 0)
return 0;
else
return 1;
}
@Override
public int getViewTypeCount() {
return 2;
}
}
https://github.com/beworker/pinned-section-listview
eW7f7MDBtUY
页:
[1]