Я настроил GridView для отображения списка продуктов. Сетка работает отлично. Когда я использую один relativeLayout, он отлично работает. Однако, когда я добавляю еще один RelativeLayout в XML элемента, чтобы добавить дополнительные сведения, прослушиватель кликов не будет вызываться.RelativeLayout, встроенный в другое RelativeLayout, вызывает ошибкуItemClickListener
определяется сетка, вместе с моим кликом слушателем, следующим образом:
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" />
и выглядит следующим образом:
Но когда я добавить следующий 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>
И должен выглядеть следующим образом:
Кто может предоставить какую-либо информацию о том, почему щелчок слушатель должен не быть вызван просто путем добавления второй RelativeLayout для элементов в GridView?
Так что ошибок на лог-коте нет. И о, да, вы работаете на Samsung? – yams
нет для обоих. Нет ошибок, и нет, я не работаю для Samsung. Я работаю в Telco, который продает телефоны от Samsung, среди прочих. – Martin
Работает ли счетчик? Попробуйте добавить 'android: descendantFocusability =" afterDescendents "' к внешнему RelativeLayout – ataulm