こんにちはstackoverflow、
私はListView
自分のページにを持っています-問題は、ある方向にスクロールしようとするたびにクラッシュすることです。これは通常ListView
ではありません。私はgithubライブラリを使用しています。
これは、 https ://github.com/terlici/DragNDropListにあります。
これが私のリストの設定です:
DragNDropListView lv = (DragNDropListView) getListView();
DragNDropSimpleAdapter adapter = new DragNDropSimpleAdapter(this, listItems, R.layout.custom_row_view, new String[]{"name", "current", "reset"}, new int[] {R.id.text1, R.id.text2, R.id.text3}, R.id.handler);
lv.setDragNDropAdapter(adapter);
更新されたログ
03-09 14:48:43.667: E/AndroidRuntime(18869): FATAL EXCEPTION: main
03-09 14:48:43.667: E/AndroidRuntime(18869): java.lang.ArrayIndexOutOfBoundsException
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.terlici.dragndroplist.DragNDropSimpleAdapter.getView(DragNDropSimpleAdapter.java:66)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.widget.AbsListView.obtainView(AbsListView.java:1409)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.widget.ListView.makeAndAddView(ListView.java:1745)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.widget.ListView.fillDown(ListView.java:670)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.widget.ListView.fillGap(ListView.java:641)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:3399)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2233)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.widget.ListView.onTouchEvent(ListView.java:3446)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.terlici.dragndroplist.DragNDropListView.onTouchEvent(DragNDropListView.java:116)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.View.dispatchTouchEvent(View.java:3885)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.os.Looper.loop(Looper.java:130)
03-09 14:48:43.667: E/AndroidRuntime(18869): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-09 14:48:43.667: E/AndroidRuntime(18869): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 14:48:43.667: E/AndroidRuntime(18869): at java.lang.reflect.Method.invoke(Method.java:507)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-09 14:48:43.667: E/AndroidRuntime(18869): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-09 14:48:43.667: E/AndroidRuntime(18869): at dalvik.system.NativeStart.main(Native Method)
03-09 14:48:48.897: I/Process(18869): Sending signal. PID: 18869 SIG: 9
このクラッシュの原因となるlibのクラス(DragNDropSimpleAdapter
66行目): `public class DragNDropSimpleAdapter extends SimpleAdapterimplements DragNDropAdapter {int mPosition []; int mHandler;
public DragNDropSimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to, int handler) {
super(context, data, resource, from, to);
mHandler = handler;
setup(data.size());
}
private void setup(int size) {
mPosition = new int[size];
for (int i = 0; i < size; ++i) mPosition[i] = i;
}
@Override
public View getDropDownView(int position, View view, ViewGroup group) {
return super.getDropDownView(mPosition[position], view, group);
}
@Override
public Object getItem(int position) {
return super.getItem(mPosition[position]);
}
@Override
public int getItemViewType(int position) {
return super.getItemViewType(mPosition[position]);
}
@Override
public long getItemId(int position) {
return super.getItemId(mPosition[position]);
}
@Override
public View getView(int position, View view, ViewGroup group) {
return super.getView(mPosition[position], view, group);
}
@Override
public boolean isEnabled(int position) {
return super.isEnabled(mPosition[position]);
}
@Override
public void onItemDrag(DragNDropListView parent, View view, int position, long id) {
}
@Override
public void onItemDrop(DragNDropListView parent, View view, int startPosition, int endPosition, long id) {
int position = mPosition[startPosition];
if (startPosition < endPosition)
for(int i = startPosition; i < endPosition; ++i)
mPosition[i] = mPosition[i + 1];
else if (endPosition < startPosition)
for(int i = startPosition; i > endPosition; --i)
mPosition[i] = mPosition[i - 1];
mPosition[endPosition] = position;
}
@Override
public int getDragHandler() {
return mHandler;
}
}
私のXMLコード
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/relativelayout" >
<LinearLayout
android:id="@+id/profile_and_reset"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relativelayout"
android:orientation="horizontal" >
<TextView
android:id="@+id/profileView"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.94"
android:layout_gravity="center_vertical"
android:textSize="18sp"/>
<Button
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/reset_button" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_below="@+id/profile_and_reset"
android:id="@+id/seperator"/>
<com.terlici.dragndroplist.DragNDropListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/seperator"
android:layout_above="@+id/second_seperator"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:id="@+id/second_seperator"
android:layout_above="@+id/add_and_instructions"/>
<LinearLayout
android:id="@+id/add_and_instructions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/relativelayout"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/add_button" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/instructions" />
</LinearLayout>
</RelativeLayout>
アップデート
通常のアクティビティに切り替えたので、この方法は機能しません。
@SuppressWarnings("unchecked")
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
if(lv.isClickable()){
super.onListItemClick(l, v, position, id);
Map<String, String> map = (Map<String, String>) lv.getAdapter().getItem(position);
String scurrents = map.get("current");
String getnames = map.get("name");
String getname = java.net.URLEncoder.encode(getnames);
int current = Integer.parseInt(scurrents);
if(current>0){
int newcurrent = current-1;
SetSql UC = new SetSql(this);
UC.open();
UC.changeCurrent(newcurrent, current, getname);
UC.close();
onResume();
}
}
}
super.onListItemClick
アクティビティには適用できないため、でエラーが発生します。どうすればこれを解決できますか?