Android SetonicClickListener不工作

Android SetonicClickListener不工作,android,android-layout,listview,android-listview,onitemclicklistener,Android,Android Layout,Listview,Android Listview,Onitemclicklistener,我已经在listview上实现了onitemCLickListener(),但它不起作用。问题是,在通过自定义适配器更新我的listview时,我通过代码向它添加了一个视图。 我也尝试过将Focusable和focusableintouch模式设置为false,也尝试过阻止子代,但我没有得到任何解决方案。请在下面找到我的代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://sc

我已经在listview上实现了onitemCLickListener(),但它不起作用。问题是,在通过自定义适配器更新我的listview时,我通过代码向它添加了一个视图。 我也尝试过将Focusable和focusableintouch模式设置为false,也尝试过阻止子代,但我没有得到任何解决方案。请在下面找到我的代码

<?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="match_parent"
android:background="@drawable/bg"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/top_greenbox"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/backArrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:padding="10dp"
        android:layout_centerVertical="true"
        android:src="@drawable/topleft_arrow" />

    <TextView
        android:id="@+id/showdate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Today is, 07 March 2014"
        android:textColor="@android:color/white" />

    <ImageView
        android:id="@+id/nextArrow"
        android:padding="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_gravity="right"
        android:src="@drawable/topright_arrow" />
</RelativeLayout>

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="60dp"
    android:descendantFocusability="blocksDescendants"
    android:smoothScrollbar="true" />

</LinearLayout>
我的布局显示时间项目是:

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

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/separator" />

<TextView
    android:id="@+id/time4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="#55b237"
    android:gravity="center"
    android:padding="10dp"
    android:text="9:45 AM"
    android:textColor="@android:color/white"
    android:textSize="14sp" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/separator" />

</LinearLayout>

这么长时间以来一直被卡住。请帮助

当您单击列表项时,
图像视图
会聚焦

将此项添加到
show\u time\u item.xml中的
LinearLayout

android:descendantFocusability="blocksDescendants"

我只是在自定义适配器的
getView()
中添加了单击侦听器。我仍然不知道为什么侦听器没有在我的活动中工作。

您可以尝试使用onclick函数

XML



在活动中,您只需编写一个函数Start。

@AnchiMittal然后在侦听器所在的位置发布更多代码。您发布了3行和XML。张贴你的适配器code@AnchitMittal同时删除此
android:genderantfocusability=“blocksDescendants”
用于
ListView
:(@AnchitMittal它应该可以工作删除
android.R.layout.simple\u spinner\u dropdown\u项用于ListView删除的android:genderantfocusability=“blocksDescendants”对于ListView。不是working@AnchitMittal同一个xml尝试了它,它没有问题。问题应该出在适配器本身上。发布适配器
getView()
code。您只发布了3行。适配器中只有这3行吗?添加了代码。请检查它是否仍然是相同的视图,以便它也适用于listview项目click listener。我知道,但不知道为什么会出现这种情况。无论如何,非常感谢您的支持。这意味着尽管我找不到合适的解决方案,但还有其他问题y、 我甚至尝试使用同一个xml进行交叉检查,结果证明它是有效的
my_list.setOnItemClickListener(new OnItemClickListener() {



        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {

            Log.e("hello","hi");

            Intent i = new Intent(ABCDListActivity.this,
                    ShowABCDProfile.class);

            i.putExtra("Doc_name", name_main);
            startActivity(i);


        }

    });
    View view = null;
    view = inflator.inflate(R.layout.doctor_list_item, null);
    ViewHolder holder = new ViewHolder();

    holder.doc_image = (ImageView) view.findViewById(R.id.doc_img);
    holder.doc_name = (TextView) view.findViewById(R.id.doc_name);
    holder.doc_qualification = (TextView) view
            .findViewById(R.id.doc_qualification);
    holder.doc_speciality = (TextView) view.findViewById(R.id.Specialities);
    holder.doc_experience = (TextView) view.findViewById(R.id.experience);


    holder.doc_experience.setText(list.get(position)
            .get(ResponseConst.TAG_STATUS_DOCTOR_EXP).toString());
    holder.doc_name.setText((list.get(position).get(
            ResponseConst.TAG_STATUS_DOCTOR_NAME).toString()));

    JSONArray hours = avail_list.get(position);

    Log.e("hours are", "size is  " + hours.length());

    LinearLayout list = (LinearLayout) view.findViewById(R.id.show_time);

    for (byte a = 0; a < hours.length(); a++) {

        try {
            JSONObject object_avail = hours.getJSONObject(a);
            String doctor_id = object_avail
                    .getString(ResponseConst.TAG_STATUS_DOCTOR_ID);
            String hour = object_avail
                    .getString(ResponseConst.TAG_STATUS_DOCTOR_AVAILABILITY_HOUR);
            String min = object_avail
                    .getString(ResponseConst.TAG_STATUS_DOCTOR_AVAILABILITY_MIN);
            String ampm = object_avail
                    .getString(ResponseConst.TAG_STATUS_DOCTOR_AVAILABILITY_AMPM);
            String status = object_avail
                    .getString(ResponseConst.TAG_STATUS_DOCTOR_AVAILABILITY_STATUS);

            String time = hour + ":" + min + " " + ampm;
            View line = list.inflate(mContext, R.layout.show_time_item, null);
            holder.time = (TextView) line.findViewById(R.id.time4);
            if(status.equals(0))
                holder.time.setTextColor(Color.GRAY);
            else holder.time.setTextColor(Color.WHITE);
            holder.time.setText(time);
            list.addView(line);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    String drawablename = "no_image.png";
    int resID = mContext.getResources().getIdentifier(drawablename,
            "drawable", mContext.getPackageName());
    holder.doc_image.setBackgroundResource(resID);


    return view;
android:descendantFocusability="blocksDescendants"
 <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="60dp"
        android:descendantFocusability="blocksDescendants"
        android:smoothScrollbar="true"
        android:onClick="Start" />