OnItemClickListener不起作用,不调用OnItemClick

时间:2016-06-02 20:06:56

标签: android onclicklistener

每当我点击列表中的项目时,我都会尝试发送Toast消息,出于某种原因,当我点击该项目时没有任何反应,

我希望你能帮助我,谢谢。

ProductList.java

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingBottom="7dp"
            android:layout_weight="1">

            <Button
                android:id="@+id/btn_minus"
                android:layout_width="35dp"
                android:layout_height="40dp"
                android:text="-" />

            <EditText
                android:id="@+id/edit_text"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:gravity="center"
                android:focusable="false"
                android:text="0" />

            <Button
                android:id="@+id/btn_plus"
                android:layout_width="35dp"
                android:layout_height="40dp"
                android:text="+" />
        </LinearLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_weight="1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="Text"
            android:textSize="15dp"
            android:textIsSelectable="true"
            android:gravity="center"
            android:id="@+id/product_name"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/product_checkBox"
            android:layout_toStartOf="@+id/product_checkBox" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:padding="5dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:id="@+id/product_checkBox" />

        </RelativeLayout>

    </LinearLayout>

</LinearLayout>

product_item_view.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@drawable/ightwall"
    android:id="@+id/drawerlayout">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
             android:layout_height="wrap_content"
            android:text="הרשימה שלי"
            android:textAlignment="center"
            android:textSize="30dp" />


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




    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ListView
            android:id="@+id/product_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:choiceMode="multipleChoice"
            android:layout_below="@+id/ChooseStore"
            >
        </ListView>

    </LinearLayout>


    </LinearLayout>
        <Button
            android:id="@+id/CalckButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/calckButton"
            android:onClick="StartCalck"
            android:layout_gravity="center" />

        <Button
            android:id="@+id/btnDel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="@string/lblBtnDel"
            />



    </LinearLayout>




    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#D5D4D4"
        android:layout_gravity="bottom">

        <ImageView
            android:id="@+id/mylist"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_mylist"
            android:adjustViewBounds="true"
            android:maxHeight="90dp"
            android:maxWidth="90dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" />

        <ImageView
            android:id="@+id/freeadd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_freetext"
            android:adjustViewBounds="true"
            android:maxHeight="90dp"
            android:maxWidth="90dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" />



        <ImageView
            android:id="@+id/favproductadd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/createlist_favproduct"
            android:adjustViewBounds="true"
            android:maxHeight="90dp"
            android:maxWidth="90dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" />



    </LinearLayout>


</LinearLayout>

pop_productlist.xml

// if isInRegion(O, A, B) is true, P is in the first region.
// otherwise, isInRegion(O, B, A) will be true.
bool isInRegion(O, A, B, P) {
    return isCCW(O, A, P) && !isCCW(O, B, P)
}

// ref: http://www.cs.cmu.edu/%7Equake/robust.html
// For more robust methods, see the link.
bool isCCW(a, b, c) {
    return ((a.x - c.x)*(b.y - c.y) - (a.y - c.y)*(b.x - c.x)) > 0;
}

1 个答案:

答案 0 :(得分:3)

您必须在祝酒词上致电.show()

更改

Toast.makeText(ProductList.this, "BLA", Toast.LENGTH_SHORT);

Toast.makeText(ProductList.this, "BLA", Toast.LENGTH_SHORT).show();