选择行时,Android Simple ListView会自动刷新

时间:2013-01-19 09:22:15

标签: android android-listview android-arrayadapter

我正在尝试找到以下问题的根源,但无法解决此问题。

这是我的代码:

   private ListView listViewRouteDownload;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.lyt_route_download);
                listViewRouteDownload = (ListView) findViewById(R.id.listViewRouteDownload);

                Object obj[]=routeDownloadHelper.routeInfo();
                beatId = (String[]) obj[0];
                beatName = (String[]) obj[1];
                adapter = new ArrayAdapter<String>(RouteDownloadActivity.this, android.R.layout.simple_list_item_multiple_choice, beatName);
                listViewRouteDownload.setAdapter(adapter);
                listViewRouteDownload.setItemsCanFocus(false);

                listViewRouteDownload.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}

上述代码中的所有内容都能正常运行, when I am selecting choices on by clicking on checkbox my the other rows of the listview gets refreshed automatically.

是的,我可以说行已刷新,请参阅示例。  如果我在行上放置了字符串15,那么通过单击其他行,listview将刷新并使15为1 (and then below) 5

以下是第一次加载列表视图时的屏幕截图。

When Loading

以下是点击复选框时的屏幕截图。

After Clicking

您可以看到第二图像,其中22变为2 (beolw that) 2。

我想解决此问题。

这是布局文件

<?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" >

    <TextView
        android:id="@+id/textViewRDTitle"
        style="@style/HeadingTheme"
        android:text="@string/route_sel" />

    <View
        android:id="@+id/viewLine1"
        style="@style/horizontalImg"
        android:layout_below="@id/textViewRDTitle" />

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:fadingEdge="none"
        android:fillViewport="true"
        android:scrollbars="none" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textViewBDRouteName"
                style="@style/ListViewHeaderTheme"
                android:gravity="center"
                android:layout_width="230dp"
                android:text="@string/route" />

            <ImageView
                android:id="@+id/imageViewselparator1"
                style="@style/ListViewHeaderSeperatorEntry"
                android:layout_height="30dp"
                android:layout_toRightOf="@id/textViewBDRouteName" />

            <TextView
                android:id="@+id/textViewBDSelecct"
                style="@style/ListViewHeaderTheme"
                android:layout_width="87dp"
                android:layout_toRightOf="@id/imageViewselparator1"
                android:gravity="center"
                android:text="@string/select" />

            <ListView
                android:id="@+id/listViewRouteDownload"
                style="@style/ListViewTheme"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/textViewBDRouteName"
                android:background="@android:color/transparent" >
            </ListView>

        </RelativeLayout>
    </HorizontalScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@drawable/button_bottom"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/buttonRDBack"
            style="@style/styleNormalButton"
            android:text="@string/back" />

        <Button
            android:id="@+id/buttonRDNext"
            style="@style/styleNormalButton"
            android:text="@string/next" />
    </LinearLayout>

</LinearLayout>

任何帮助都是适当的。

谢谢你。

1 个答案:

答案 0 :(得分:0)

尝试这个xml,虽然我删除了你在那里的一个“View”(第7行),你可能想要替换它。 这个xml对我来说很好,没有错误,我想问题是你遗漏了很多宽度参数?或者它们包含在我看不到的样式中,但在某处你应该找到错误:

    <?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" >

        <TextView
            android:id="@+id/textViewRDTitle"
            style="@style/HeadingTheme"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/route_sel" />

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fadingEdge="none"
            android:fillViewport="true"
            android:scrollbars="none" >

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/textViewBDRouteName"
                    style="@style/ListViewHeaderTheme"
                    android:layout_width="230dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="@string/route" />

                <ImageView
                    android:id="@+id/imageViewselparator1"
                    style="@style/ListViewHeaderSeperatorEntry"
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:layout_toRightOf="@id/textViewBDRouteName" />

                <TextView
                    android:id="@+id/textViewBDSelecct"
                    style="@style/ListViewHeaderTheme"
                    android:layout_width="87dp"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@id/imageViewselparator1"
                    android:gravity="center"
                    android:text="@string/select" />

                <ListView
                    android:id="@+id/listViewRouteDownload"
                    style="@style/ListViewTheme"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/textViewBDRouteName"
                    android:background="@android:color/transparent" >
                </ListView>

            </RelativeLayout>
        </HorizontalScrollView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:background="@drawable/button_bottom"
            android:gravity="center"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/buttonRDBack"
                style="@style/styleNormalButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/back" />

            <Button
                android:id="@+id/buttonRDNext"
                style="@style/styleNormalButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/next" />

        </LinearLayout>

</LinearLayout>