私は BaseAdapter を使用しています:
public class MyAdapter extends BaseAdapter{
private final LayoutInflater mInflater;
private final String[] mItems;
private final String[] mClasses;
private final Drawable[] mIcons;
private final Integer mii;
public MyAdapter(Activity c, String[] objects, Drawable[] dricons, String[] classes, Integer ii) {
mInflater = c.getLayoutInflater();
mClasses = classes;
mItems = objects;
mIcons = dricons;
mii = ii;
}
public int getCount() {
return mItems.length;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listitem, null);
}
((TextView)convertView).setCompoundDrawablesWithIntrinsicBounds( mIcons[position], null, null, null);
((TextView)convertView).setText(mItems[position]);
((TextView)convertView).setTag(mClasses[position]);
return convertView;
}
@Override
public Object getItem(int position) {
return mItems[position];
// return mClasses[position];
}
@Override
public long getItemId(int position) {
return position;
}
}
ListView を下にスクロールすると、リストの半分がスクロールされた後にアプリケーションが suxh 例外をスローします。
12-26 19:39:36.020: E/AndroidRuntime(11800): FATAL EXCEPTION: main
12-26 19:39:36.020: E/AndroidRuntime(11800): java.lang.ArrayIndexOutOfBoundsException
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.tsysv.widgetchanger.MyAdapter.getView(MyAdapter.java:38)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.AbsListView.obtainView(AbsListView.java:1294)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.ListView.makeAndAddView(ListView.java:1727)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.ListView.fillDown(ListView.java:652)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.ListView.fillGap(ListView.java:623)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:2944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2065)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.ListView.onTouchEvent(ListView.java:3315)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.View.dispatchTouchEvent(View.java:3765)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:905)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1701)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.app.Activity.dispatchTouchEvent(Activity.java:2093)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1685)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewRoot.handleMessage(ViewRoot.java:1802)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.os.Looper.loop(Looper.java:144)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.app.ActivityThread.main(ActivityThread.java:4937)
12-26 19:39:36.020: E/AndroidRuntime(11800): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 19:39:36.020: E/AndroidRuntime(11800): at java.lang.reflect.Method.invoke(Method.java:521)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-26 19:39:36.020: E/AndroidRuntime(11800): at dalvik.system.NativeStart.main(Native Method)
どうしたの?