2013-07-02 25 views
0

我已經設置了一個GridView來顯示產品列表。網格工作正常。當我使用一個relativeLayout時,它效果很好。但是,當我在項目XML中添加另一個RelativeLayout以包含其他詳細信息時,將不會調用點擊偵聽器。RelativeLayout與另一個RelativeLayout嵌入導致onItemClickListener失敗

網格的定義,與我的點擊聽衆一起,如下:

gridview = (GridView) findViewById(R.id.browse_devices); 
    gridview.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View v, int position, long id) { 

       Intent intent = new Intent(mContext,ShowProductDetail.class); 
       Bundle bundle = new Bundle(); 
       bundle.putString("SKU", skuList.get(position)); 
       intent.putExtras(bundle); 
       startActivity(intent); 
     } 
    }); 

我的項目說明,如果我剛纔的標題,一些字幕和產品形象,點擊收聽工作正常,並點擊產品會導致ShowProductDetail活動啓動。這定義是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginTop="5dp" 
android:background="@color/off_white" > 

<TextView 
    android:id="@+id/br_product_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="4dp" 
    android:text="Medium Text" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="@color/devil_gray" /> 

<TextView 
    android:id="@+id/br_product_subtitle0" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/br_product_title" 
    android:layout_marginTop="8dp" 
    android:text="TextView" 
    android:textColor="@color/devil_gray" /> 

<TextView 
    android:id="@+id/br_product_subtitle1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/br_product_subtitle0" 
    android:layout_marginTop="4dp" 
    android:text="TextView" 
    android:textColor="@color/devil_gray" /> 

<TextView 
    android:id="@+id/br_product_subtitle2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/br_product_subtitle1" 
    android:layout_marginTop="4dp" 
    android:text="TextView" /> 

<ImageView 
    android:id="@+id/separator" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/br_product_title" 
    android:src="@drawable/separator_black" /> 


    <ImageView 
     android:id="@+id/br_product_image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical|center_horizontal" /> 

,看起來像這樣: enter image description here

但是當我添加下面的XML,以使用戶能夠選擇內存,顏色和數量,點擊監聽器永遠不會被調用。這是我加入到下方的額外的RelativeLayout:

<RelativeLayout 
    android:id="@+id/details_layout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/br_product_image" 
    android:layout_marginTop="5dp" 
    android:background="@color/off_white" > 

    <TextView 
     android:id="@+id/capacity_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="false" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="false" 
     android:text="@string/device_mem" /> 

    <TextView 
     android:id="@+id/color_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="10dp" 
     android:layout_toRightOf="@+id/capacity_title" 
     android:text="@string/device_color" /> 

    <TextView 
     android:id="@+id/quantity_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="40dp" 
     android:layout_toRightOf="@+id/color_title" 
     android:text="@string/quantity" /> 

    <Spinner 
     android:id="@+id/memory_spinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignEnd="@id/capacity_title" 
     android:layout_alignStart="@id/capacity_title" 
     android:layout_below="@id/capacity_title" /> 

    <Spinner 
     android:id="@+id/color_spinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignEnd="@id/color_title" 
     android:layout_alignStart="@id/color_title" 
     android:layout_below="@+id/color_title" /> 

    <Spinner 
     android:id="@+id/quantity_spinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignEnd="@id/quantity_title" 
     android:layout_alignStart="@id/quantity_title" 
     android:layout_below="@+id/quantity_title" /> 

    <TextView 
     android:id="@+id/device_price" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="false" 
     android:layout_alignParentLeft="false" 
     android:layout_below="@id/memory_spinner" 
     android:text="$199.99" 
     android:textSize="30sp" /> 

    <Button 
     android:id="@+id/buy_now" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/quantity_spinner" 
     android:layout_marginLeft="20dp" 
     android:layout_toRightOf="@id/device_price" 
     android:background="@drawable/btn_buy_now" /> 

</RelativeLayout> 

而且應該是這樣的: enter image description here

任何人都可以提供的任何信息,爲什麼點擊收聽應該不能被添加簡稱第二個RelativeLayout到GridView中的項目?

+0

所以沒有日誌貓的錯誤。噢,你是否爲三星工作? – yams

+0

否。沒有錯誤,不,我不爲三星工作。我爲三星出售手機的Telco工作,等等。 – Martin

+0

微調工作?嘗試添加'android:descendantFocusability =「afterDescendents」'到外面的RelativeLayout – ataulm

回答

0

我建議在兩個行上的每個孩子上使用2個LinearLayouts,並使用相同的權重。這對所有設備都是通用的。 GridView在方向和較小設備的變化上會有不成比例的列寬。