我试图在我的项目中使用Swipelistview但它抛出 NullPointer 说:
java.lang.NullPointerException
at com.fortysevendeg.swipelistview.SwipeListViewTouchListener.setFrontView(SwipeListViewTouchListener.java:138)
at com.fortysevendeg.swipelistview.SwipeListViewTouchListener.onTouch(SwipeListViewTouchListener.java:731)
at com.fortysevendeg.swipelistview.SwipeListView.onInterceptTouchEvent(SwipeListView.java:630)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1852)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209) 在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
我通过以下方式实现了该库:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.fortysevendeg.swipelistview.SwipeListView
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="35dp"
android:layout_marginTop="51dp"
android:listSelector="#00000000"
swipe:swipeActionLeft="dismiss"
swipe:swipeActionRight="dismiss"
swipe:swipeAnimationTime="1000"
swipe:swipeBackView="@+id/back"
swipe:swipeCloseAllItemsWhenMoveList="false"
swipe:swipeFrontView="@+id/front"
swipe:swipeMode="both"
swipe:swipeOffsetLeft="20dp"
swipe:swipeOffsetRight="20dp"
swipe:swipeOpenOnLongPress="false" />
</LinearLayout>
这是代码:
private SwipeListView listview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
States states_name[] = new States[] {
new States("Item 1", "Item A"),
new States("Item 2", "Item B"),
new States("Item 3", "Item C"),
new States("Item 4", "Item D"),
new States("Item 5", "Item E"),
new States("Item 6", "Item F"),
new States("Item 7", "Item G"),
new States("Item 8", "Item H")
};
StateAdapter adapter = new StateAdapter(this, R.layout.listtoinflate, states_name);
listview1 = (SwipeListView)findViewById(R.id.listView1);
listview1.setAdapter(adapter);
}