OnItemCLickListener在ListView自定义适配器中不起作用

杰伊·维斯(Jay Vyas)

我有两个活动。一个显示所有产品在一个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();
         }
       });
吉加尔·谢赫(Jigar Shekh)

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" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

具有自定义适配器的Listview在SherlockFragment中不起作用

来自分类Dev

自定义适配器ListView,setOnCheckedChangeListener不起作用

来自分类Dev

notifyDatasetChanged在Android中的自定义适配器的getView()方法中不起作用

来自分类Dev

Android Java-Glide在自定义适配器中不起作用

来自分类Dev

如果条件在自定义适配器中不起作用(getView())

来自分类Dev

AsyncTask在自定义适配器中不起作用

来自分类Dev

更改自定义适配器onClick回调中的边距不起作用,Android

来自分类Dev

自定义对话框在适配器中不起作用,应用程序崩溃

来自分类Dev

Rhom的Ember-Data自定义适配器-FindAll不起作用

来自分类Dev

Android:使用带自定义适配器的notifyDataSetChanged()刷新ListFragment不起作用

来自分类Dev

自定义微调器适配器不起作用

来自分类Dev

用于Ember Data的自定义适配器不起作用

来自分类Dev

带notifyDataSetChanged的自定义适配器不起作用

来自分类Dev

自定义基本适配器不起作用过滤器

来自分类Dev

ListView的自定义适配器

来自分类Dev

自定义ListView的适配器

来自分类Dev

自定义ListView适配器中的NullPointerException

来自分类Dev

在自定义适配器中遍历ListView

来自分类Dev

OnItemClickListener不起作用,但OnLongItemClickListener在自定义Listview中起作用

来自分类Dev

Android Studio中带有自定义适配器的自定义ListView

来自分类Dev

使用自定义适配器的ListView中的自定义行

来自分类Dev

ListView自定义适配器丢失imageView

来自分类Dev

自定义适配器显示RuntimeException-ListView

来自分类Dev

使用自定义适配器过滤ListView

来自分类Dev

自定义listview适配器上的OnclickListner

来自分类Dev

ListView自定义适配器重复项

来自分类Dev

自定义基础适配器到ListView

来自分类Dev

使用自定义适配器从listview搜索项目

来自分类Dev

Android ListView onClickListener自定义适配器

Related 相关文章

  1. 1

    具有自定义适配器的Listview在SherlockFragment中不起作用

  2. 2

    自定义适配器ListView,setOnCheckedChangeListener不起作用

  3. 3

    notifyDatasetChanged在Android中的自定义适配器的getView()方法中不起作用

  4. 4

    Android Java-Glide在自定义适配器中不起作用

  5. 5

    如果条件在自定义适配器中不起作用(getView())

  6. 6

    AsyncTask在自定义适配器中不起作用

  7. 7

    更改自定义适配器onClick回调中的边距不起作用,Android

  8. 8

    自定义对话框在适配器中不起作用,应用程序崩溃

  9. 9

    Rhom的Ember-Data自定义适配器-FindAll不起作用

  10. 10

    Android:使用带自定义适配器的notifyDataSetChanged()刷新ListFragment不起作用

  11. 11

    自定义微调器适配器不起作用

  12. 12

    用于Ember Data的自定义适配器不起作用

  13. 13

    带notifyDataSetChanged的自定义适配器不起作用

  14. 14

    自定义基本适配器不起作用过滤器

  15. 15

    ListView的自定义适配器

  16. 16

    自定义ListView的适配器

  17. 17

    自定义ListView适配器中的NullPointerException

  18. 18

    在自定义适配器中遍历ListView

  19. 19

    OnItemClickListener不起作用,但OnLongItemClickListener在自定义Listview中起作用

  20. 20

    Android Studio中带有自定义适配器的自定义ListView

  21. 21

    使用自定义适配器的ListView中的自定义行

  22. 22

    ListView自定义适配器丢失imageView

  23. 23

    自定义适配器显示RuntimeException-ListView

  24. 24

    使用自定义适配器过滤ListView

  25. 25

    自定义listview适配器上的OnclickListner

  26. 26

    ListView自定义适配器重复项

  27. 27

    自定义基础适配器到ListView

  28. 28

    使用自定义适配器从listview搜索项目

  29. 29

    Android ListView onClickListener自定义适配器

热门标签

归档