作者:忘不了那个你 | 来源:互联网 | 2023-05-22 23:30
我尝试使用两种类型的视图和两种类型的ViewHolrdes,但收到错误:
java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6705)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5210)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4368)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
at android.view.Choreographer.doCallbacks(Choreographer.java:579)
at android.view.Choreographer.doFrame(Choreographer.java:547)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
这是我的适配器:
public class FriendsListAdapterFromKesh extends ArrayAdapter {
List friends;
List friendsWithoutPoints;
Context context;
private LayoutInflater inflater;
private LayoutInflater mLayoutInflater;
private static String ROOT_DIRECTORY_PATH = Environment.getExternalStorageDirectory() + File.separator + ".SleepKeeker/Photos old";
FriendsTab friendsTab;
public FriendsListAdapterFromKesh(Context context, final List friends, final List friendsWithoutPoints) {
super(context, 0);
this.cOntext= context;
inflater = LayoutInflater.from(context);
this.friendsWithoutPoints = friendsWithoutPoints;
this.friends = friends;
friendsTab = new FriendsTab();
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void updateList(List newlist1, List newlist2) {
friends.clear();
friends.addAll(newlist1);
friendsWithoutPoints.clear();
friendsWithoutPoints.addAll(newlist2);
this.notifyDataSetChanged();
}
public List getFriends() {
return friends;
}
@Override
public int getCount() {
return friends.size() + friendsWithoutPoints.size();
}
public String getIdSocTypeName(int position) {
if (friends == null || position + 1 >= friends.size()) {
return "";
}
FriendListEntryItem ei = friends.get(position - 1);
return ei.userId + "," + ei.socType + "," + ei.name;
}
static class ViewHolder1 {
public ImageView image = null;
public TextView title = null;
public TextView subtitle = null;
}
static class ViewHolder2 {
public ImageView image;
public TextView title;
public TypefacedButton button;
}
@Override
public int getItemViewType(int pos) {
if (pos
滚动列表时出现错误.但我不明白为什么.我花了很多时间来解决这个问题,但无济于事
1> stkent..:
更换
@Override
public int getItemViewType(int pos) {
if (pos
通过
@Override
public int getItemViewType(int pos) {
if (pos
从方法的适配器文档getItemViewType
(我的重点):
返回
表示View类型的整数.如果可以在getView(int,View,ViewGroup)中将一个视图转换为另一个视图,则两个视图应共享相同的类型.注意:整数必须在0到getViewTypeCount() - 1的范围内.也可以返回IGNORE_ITEM_VIEW_TYPE.
此时,您将返回视图类型的值1和2.您需要返回值0和1,以满足粗体条件.