你好計算器,列表視圖崩潰時滾動
我我的網頁上有一個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);
修訂LOGACT
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擴展了SimpleAdapter,實現了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>
UPDATE
現在,我切換到普通的活動,這種方法是行不通的:
@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
,因爲它不適用於活動。我該如何解決這個問題?
它,因爲你正在訪問陣列出來的指標後你的代碼獲得更多幫助 – DjHacktorReborn 2013-03-09 11:17:43
@DjHacktorReborn我沒有訪問任何數組..雖然,我會發布該代碼中給出錯誤的libs代碼。 – arielschon12 2013-03-09 11:21:26
@DjHacktorReborn更多附加程序碼! – arielschon12 2013-03-09 11:23:46