如何在android中将列表视图强制转换为PullToRefreshListView时修复类强制转换异常
我正在应用程序中使用ListActivity。我想在应用程序中为ListView实现PullToRefreshListView。我已经实现了以下代码。我遇到了ClassCast异常。有人能告诉我如何修复它吗如何在android中将列表视图强制转换为PullToRefreshListView时修复类强制转换异常,android,Android,我正在应用程序中使用ListActivity。我想在应用程序中为ListView实现PullToRefreshListView。我已经实现了以下代码。我遇到了ClassCast异常。有人能告诉我如何修复它吗 ((PullToRefreshListView)getListView()).setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() {
((PullToRefreshListView)getListView()).setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
Log.v("Inside the refresh","Inside the List");
// TODO Auto-generated method stub
//Add Web Service here
//Constants.isQueueRefreshing=true;
//new NewDataTask().execute();
}
});
logcat错误:
03-13 12:11:26.854: E/AndroidRuntime(5242): FATAL EXCEPTION: main
03-13 12:11:26.854: E/AndroidRuntime(5242): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.JobQueueDetailDescription}: java.lang.ClassCastException: android.widget.ListView
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1713)
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1738)
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.app.ActivityThread.access$1500(ActivityThread.java:124)
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:980)
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.os.Looper.loop(Looper.java:130)
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.app.ActivityThread.main(ActivityThread.java:3906)
03-13 12:11:26.854: E/AndroidRuntime(5242): at java.lang.reflect.Method.invokeNative(Native Method)
03-13 12:11:26.854: E/AndroidRuntime(5242): at java.lang.reflect.Method.invoke(Method.java:507)
03-13 12:11:26.854: E/AndroidRuntime(5242): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840)
03-13 12:11:26.854: E/AndroidRuntime(5242): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
03-13 12:11:26.854: E/AndroidRuntime(5242): at dalvik.system.NativeStart.main(Native Method)
03-13 12:11:26.854: E/AndroidRuntime(5242): Caused by: java.lang.ClassCastException: android.widget.ListView
03-13 12:11:26.854: E/AndroidRuntime(5242): at com.test.JobQueueDetailDescription.onCreate(JobQueueDetailDescription.java:40)
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-13 12:11:26.854: E/AndroidRuntime(5242): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1677)
03-13 12:11:26.854: E/AndroidRuntime(5242): ... 11 more
使用普通活动而不是listactivity 并将pulltorefreshlistview添加到布局xml中 那只有你才能掩盖它
<com.example.lotm.util.PullToRefreshListView
android:id="@+id/LotListView"
android:layout_height="fill_parent"
android:layout_below="@+id/progress_bar"
android:layout_width="fill_parent"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"
android:listSelector="@android:color/transparent" />
发布您的日志,然后链接到OP似乎正在使用。是否可以在LIstActivity中实现PullToRefreshListView