在HorizontaListView(android)中滚动时出现问题
我使用在HorizontaListView(android)中滚动时出现问题,android,listview,android-listview,scroll,Android,Listview,Android Listview,Scroll,我使用HorizontalListView滚动我使用下面的代码(方法setOnItemClickListener) 但当位置达到3或更高时出现问题,然后我得到一个错误: 12-28 01:33:37.814 20841-20841/com.example.SmsService E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.SmsService, PID: 20841 java.lang.NullPointerExcep
HorizontalListView
滚动我使用下面的代码(方法setOnItemClickListener)
但当位置达到3
或更高时出现问题,然后我得到一个错误:
12-28 01:33:37.814 20841-20841/com.example.SmsService E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.SmsService, PID: 20841
java.lang.NullPointerException
at com.example.SmsService.VideoView$1$1.run(VideoView.java:68)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
我认为这可能是因为我使用了循环列表视图:
@Override
public int getCount() {
return Integer.MAX_VALUE;//
}
我如何解决这个问题?也许还有其他方法可以滚动列表视图?(平滑滚动不起作用)和.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1" android:id="@+id/ll">
<VideoView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/videoView"
android:layout_gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="150dp" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_marginBottom="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/listview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true" android:layout_weight="1"/>
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:smoothScrollbar="true"
android:clickable="true" android:layout_alignParentRight="true" android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
更改此行
public void run() {
int centerX = listview.getChildAt(position).getLeft();
listview.scrollTo(centerX)
}
到
您可能需要找到另一种方式来移动项目。此代码将只修复空指针异常。水平滚动视图中有多少项?哪一个是ViedoView.java中的第68行?@Rohit5k2,如果你的意思是屏幕上可以看到多少,3-4@Rohit5k2,“哪一个是ViedoView.java中的第68行?”-its-“int centerX=listview.getChildAt(position).getLeft();“否。项目总数???@Rohit5k2,它循环的listview编号可能是“Integer.MAX_VALUE”,但是你能问一下‘私有静态字符串[]数据对象=新字符串[]{“Text#1”“Text#2”“Text#3”,“Text#4”,“Text#5”};'是的,我明白,但我不明白为什么如果position=3我会出错,因为在我的“listView->child”中有位置3?您可能需要再次查看完整的代码。我现在看不到。那么,如何在“Listview”中切换到下一个“child”以在屏幕中心滚动呢?
public void run() {
int centerX = listview.getChildAt(position).getLeft();
listview.scrollTo(centerX)
}
public void run() {
View v = listView.getChildAt(position);
if(v != null)
{
int centerX = v.getLeft();
listview.scrollTo(centerX);
}
}