OnItemCLickListener не работает в пользовательском адаптере ListView

У меня два вида деятельности. Один отображает все продукты в ListView. Второе действие запускается при выборе элемента. По сути, второе действие должно запускаться при щелчке элемента, и оно должно открывать файл PDF.

Ну, дело в том, что он не запускает вторую активность при выборе элемента. Размещение кода для вашей справки.

Мой .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="wrap_content"
    android:layout_margin="5dp"
    android:background="@drawable/list_bacg"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/productImage"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="0.25"
        android:adjustViewBounds="true"
        android:padding="5dp"
        android:src="@drawable/ic_launcher" />

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp" >

            <!--
             <TextView 
            android:layout_width="0dp"
            android:layout_weight="0.5"
            android:layout_height="wrap_content"
            android:text="Product Name"
            />
            -->

            <TextView
                android:id="@+id/prodName"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:text="Prod Name"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingBottom="2dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Price: "
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/storePrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/hori_line"
                android:text="Store Price"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingBottom="2dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Offer Price: "
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/offerPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Offer Price"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </LinearLayout>

        <RatingBar
            android:id="@+id/ratingbar_prod"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dip" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="5dp" >

            <!--
              <TextView 
            android:layout_width="0dp"
            android:layout_weight="0.5"
            android:layout_height="wrap_content"
            android:text="Category Name"
            />
            -->

            <TextView
                android:id="@+id/storeName"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:text="Store Name"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="0.2"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/prodCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/pc_edit_b"
            android:inputType="number" />
    </LinearLayout>

</LinearLayout>

Это настраиваемый вид, который я хочу установить на ListView.

А это файл с кодом.

    listView = (ListView)rootView.findViewById(R.id.lv);
    List<StoreProducts> objects = new ArrayList<StoreProducts>();
    storeInfoAdapter = new    StoreInfoAdapter(getActivity(),android.R.layout.simple_list_item_1,objects);
    listView.setAdapter(storeInfoAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            Log.e("Click", "Click");
            StoreProducts productDetails = (StoreProducts) parent.getItemAtPosition(position);
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
             fragmentTransaction.setCustomAnimations(R.anim.ani_out,R.anim.ani_in);
            fragmentTransaction.replace(R.id.frame_container,new                ProductDescFragment(productDetails));
            fragmentTransaction.addToBackStack("All Products");
            fragmentTransaction.commit();
         }
       });

person Jay Vyas    schedule 13.12.2014    source источник
comment
onItemClick успешно получает событие касания?   -  person JASON G PETERSON    schedule 13.12.2014
comment
нет ... я так не думаю, потому что я поместил журнал в этот метод, и он не печатается   -  person Jay Vyas    schedule 13.12.2014
comment
Тогда что-то еще может потреблять событие касания, возможно, EditText, но мне не ясно, где ListView находится в вашем общем макете.   -  person JASON G PETERSON    schedule 13.12.2014
comment
listview находится в mainLayout.   -  person Jay Vyas    schedule 13.12.2014


Ответы (3)


Добавление android:focusable="false" к каждому из настраиваемых элементов макета. например. ваш пользовательский элемент макета

<EditText 
 android:id="@+id/prodCount"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:background="@drawable/pc_edit_b"
 android:inputType="number"
 android:focusable="false" />
person Jigar Shekh    schedule 13.12.2014

Пытаться

AdapterView.OnItemClickListener()
person Don Chakkappan    schedule 13.12.2014
comment
Не могли бы вы обновить вопрос с вашим новым фрагментом кода - person Don Chakkappan; 13.12.2014

У меня была аналогичная проблема. У меня был флажок в представлении. После снятия флажка onItemClickListener заработал. Сегодня я экспериментировал с EditText в представлении. Та же проблема onItemClickListener не вызывается, удалите EditText из представления, он работает.

person Nookaraju Koneti    schedule 21.05.2019