listView.setOnItemClickListener()在Android中不起作用

时间:2015-11-18 11:09:41

标签: android xml listview android-listview

在我的xml中有两个列表视图(Area1和Area2),在Area2中有动态元素,当我点击任何项目时,它应该填充在Area1(另一个listview,其大小始终为1)。我的问题是itemClickListener无法正常工作。

enter image description here

XML是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_grey" 
>

<RelativeLayout
    android:id="@+id/top1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"

 android:background="@drawable/listrow_layerlist_background_dark_purple"
        android:padding="10dp" >

        <LinearLayout
            android:id="@+id/linear_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView_productName_size_color"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="&lt;Scan or Type a Barcode to see Product    
 information here>"
                android:paddingLeft="5dp"
                android:textSize="12dp" />

            <LinearLayout
                android:id="@+id/linear1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="7dp"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:orientation="horizontal"
                android:weightSum="7.5" >

                <ToggleButton
                    android:id="@+id/toggleButton1"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.5"
                    android:background="@drawable/bgtoggle"
                    android:button="@null"
                    android:checked="true"
                    android:textOff=""
                    android:textOn="" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="3.5"
                    android:nextFocusLeft="@+id/editText_Price"
                    android:nextFocusUp="@+id/editText_Price" >

                    <EditText
                        android:id="@+id/editText_barcode"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"

                        android:ems="10"
                        android:gravity="bottom"
                        android:hint="Barcode"
                        android:longClickable="false"
                        android:singleLine="true"
                        android:textAppearance="?
android:attr/textAppearanceMedium"
                        android:textColor="@color/black" >

                        <requestFocus />
                    </EditText>
                </LinearLayout>

                <EditText
                    android:id="@+id/editText_Price"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0"
                    android:visibility="visible" />

                <LinearLayout
                    android:id="@+id/linear_fetch_barcode_data"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginRight="2dp"
                    android:layout_weight="1"
                    android:background="@drawable/listrow_layerlist_image"
                    android:gravity="center_vertical|center_horizontal" >

                    <ImageView
                        android:id="@+id/fetch_barcode_data"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/forward" />
                </LinearLayout>

                <Button
                    android:id="@+id/button1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/align"
                    android:layout_alignTop="@+id/align"
                    android:layout_weight="1.5"
                    android:background="@drawable/camera_new"
                    android:textColor="@color/white"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/top"
        android:background="@color/dark_color"
        android:visibility="visible" >

        <!-- <TextView -->
        <!-- android:id="@+id/total_scanned_pending_jobs" -->
        <!-- android:layout_width="fill_parent" -->
        <!-- android:layout_height="fill_parent" -->
        <!-- android:layout_margin="5dp" -->
        <!-- android:background="@drawable/rounded_edittext" -->
        <!-- android:gravity="left" -->
        <!-- android:paddingBottom="2dp" -->
        <!-- android:paddingLeft="8dp" -->
        <!-- android:paddingRight="8dp" -->
        <!-- android:paddingTop="2dp" -->
        <!-- android:singleLine="true" -->
        <!-- android:textColor="@color/black" -->
        <!-- android:textSize="11sp" /> -->

        <LinearLayout
            android:id="@+id/rl_first_block"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/dark_color"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="2dp"
            android:visibility="visible"
            android:weightSum="2" >

            <LinearLayout
                android:id="@+id/rl_first_block1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:layout_weight="1"
                android:background="@drawable/bg_header_left"
                android:orientation="vertical"
                android:paddingBottom="2dp"
                android:paddingLeft="8dp"
                android:paddingRight="8dp"
                android:paddingTop="2dp" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:weightSum="2" >

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:orientation="horizontal" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Products:"
                            android:textAppearance="?
 android:attr/textAppearanceSmallInverse"
                            android:textColor="@color/black"
                            android:textStyle="bold" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:orientation="horizontal" >

                        <TextView
                            android:id="@+id/txtProducts"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:ellipsize="end"
                            android:gravity="right"
                            android:singleLine="true"
                            android:text="£ 2221245"
                            android:textAppearance="?
 android:attr/textAppearanceSmallInverse"
                            android:textColor="@color/black"
                            android:textStyle="bold" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/rl_first_block12"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:weightSum="2" >

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:orientation="horizontal" >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Quantity:"
                            android:textAppearance="?
 android:attr/textAppearanceSmallInverse"
                            android:textColor="@color/black"
                            android:textStyle="bold" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:orientation="horizontal" >

                        <TextView
                            android:id="@+id/txtQuantity"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:ellipsize="end"
                            android:gravity="right"
                            android:singleLine="true"
                            android:text="£ 298989"
                            android:textAppearance="?
 android:attr/textAppearanceSmallInverse"
                            android:textColor="@color/black"
                            android:textStyle="bold" />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            <!-- new -->

            <LinearLayout
                android:id="@+id/rl_first_block2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="1dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:layout_weight="1"
                android:background="@drawable/bg_header_right"
                android:gravity="center"
                android:orientation="vertical"
                android:paddingBottom="2dp"
                android:paddingLeft="8dp"
                android:paddingRight="8dp"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Total (After Discounts)"
                    android:textColor="@color/black"
                    android:textSize="11sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/totalAmt_after_discounts"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:singleLine="true"
                    android:text="£ 2343233252"
                    android:textAppearance="?    
 android:attr/textAppearanceMedium"
                    android:textColor="@color/purple"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/rl_bottom_btns"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:weightSum="4" >

        <Button
            android:id="@+id/btn_total_draft"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_weight="1"
            android:background="@color/darkgrey"
            android:orientation="horizontal"
            android:text=""
            android:textAllCaps="false"
            android:textColor="@color/white"
            android:textSize="15sp" />

        <Button
            android:id="@+id/btn_save_draft"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/darkgrey"
            android:orientation="horizontal"
            android:text="New"
            android:textColor="@color/white"
            android:textSize="15sp" />

        <Button
            android:id="@+id/btn_goto_draft"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_weight="1"
            android:background="@color/darkgrey"
            android:orientation="horizontal"
            android:text="Open"
            android:textColor="@color/white"
            android:textSize="15sp" />

        <Button
            android:id="@+id/button_next"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_weight="1"
            android:background="@color/darkgrey"
            android:orientation="horizontal"
            android:text="Tender"
            android:textColor="@color/white"
            android:textSize="15sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/linear"
        android:layout_marginLeft="2dp"
        android:orientation="horizontal"
        android:visibility="gone" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:enabled="false"
            android:gravity="center"
            android:text="Barcode"
            android:textColor="@android:color/black"
            android:textSize="20sp"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:enabled="false"
            android:gravity="center"
            android:text="Qty"
            android:textColor="@android:color/black"
            android:textSize="20sp"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:enabled="false"
            android:gravity="center"
            android:text="Area"
            android:textColor="@android:color/black"
            android:textSize="20sp"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:enabled="false"
            android:gravity="center"
            android:text="Location"
            android:textColor="@android:color/black"
            android:textSize="20sp"
            android:textStyle="bold" >
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/inflated_ll"
        android:layout_marginLeft="2dp"
        android:orientation="horizontal"
        android:visibility="gone"
        android:weightSum="4" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_weight="0.6"
            android:enabled="false"
            android:gravity="left"
            android:paddingLeft="3dp"
            android:text="Name"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_weight="1.5"
            android:enabled="false"
            android:gravity="right"
            android:text="Quantity"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_weight="0.5"
            android:enabled="false"
            android:gravity="right"
            android:text="Price"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="1dp"
            android:layout_weight="0.6"
            android:enabled="false"
            android:gravity="center"
            android:text="Total"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:textStyle="bold" >
        </TextView>
    </LinearLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/rl_bottom_btns"
        android:layout_below="@id/inflated_ll"
        android:layout_marginTop="20dp"
        android:divider="@null"
        android:descendantFocusability="blocksDescendants"
         android:focusable="false"

         android:focusableInTouchMode="false"
          android:clickable="false"

        >
    </ListView>

    <ListView
        android:id="@+id/inflated_ll"
        android:layout_width="match_parent"
        android:layout_height="86dp"
        android:layout_below="@+id/linear"
        android:background="#80000000"
        android:gravity="center"
        android:orientation="vertical"

        android:visibility="gone" >
    </ListView>
</RelativeLayout>

</RelativeLayout>
[enter image description here][1]

2 个答案:

答案 0 :(得分:0)

如果您想更改ListView中显示的数据,则需要拨打填充notifyDataSetChanged()的适配器上的ListView

因此,单击该按钮时,请更改适配器中的数据并调用notifyDataSetChanged()

答案 1 :(得分:0)

尝试设置

android:descendantFocusability="blocksDescendants">

到父布局并设置

android:clickable="false"
    android:focusable="false">

对所有观看,这将使itemClickListener运作良好。