0

我有一个列表视图,我正在为该列表视图使用 OnItemClickListener。同时,在我的自定义适配器的getview方法中,我对整个行视图使用onclicklistener。我发现在自定义适配器中使用Onclicklistener时,我的listview的OnItemClickListener没有被触发。我想同时使用这两个监听器。任何人都可以帮我做吗?提前致谢。

我的列表视图监听器,

list_specialists.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                HashMap<String, String> trends_data= new HashMap<String, String>();
                trends_data = specobj.get(position);
                specialist.setText(trends_data.get(KEY_SPEC_TITLE));

                new GetTime(BookingActivity.this).execute();


                }
            });

还有我在自定义适配器中的 getview 方法,

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = convertView;
    final ViewHolder holder;

    if (rowView == null) {
        rowView = inflater.inflate(R.layout.row_timeslot, parent, false);
        holder = new ViewHolder();
        holder.title = (TextView) rowView.findViewById(R.id.textView2);
        holder.layout = (RelativeLayout) rowView
                .findViewById(R.id.relativeLayout1);
        holder.check = (org.holoeverywhere.widget.CheckBox) rowView
                .findViewById(R.id.checkBox1);

        rowView.setTag(holder);
    } else {
        holder = (ViewHolder) rowView.getTag();
    }

    HashMap<String, String> trends_data = new HashMap<String, String>();
    trends_data = trendsobj.get(position);

    holder.check.setId(position);

    holder.check.setChecked(checkarry[position]);

    // for managing the state of the boolean
    // array according to the state of the
    // CheckBox

    holder.check.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            for (int i = 0; i < checkarry.length; i++) {
                if (position == i) {
                    checkarry[i] = true;
                } else {
                    checkarry[i] = false;
                }

                RefreshList();
            }
        }
    });

    holder.layout.setOnClickListener(new View.OnClickListener() { // Here I am using onclicklistener for rows's parent layout.

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub




            for (int i = 0; i < checkarry.length; i++) {
                if (position == i) {
                    checkarry[i] = true;
                } else {
                    checkarry[i] = false;
                }

                RefreshList();
            }



        }
    });

    holder.title.setText(trends_data.get(BookingActivity.KEY_TIME_TITLE));



    return rowView;
}

行布局xml文件...

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:focusable="false"
    android:background="@drawable/list_selector"
    android:orientation="vertical"
    android:padding="16dp" >

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/activity_googlecards_card_imageview"
        android:text="Rate "
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#757572" />

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/textView3"
        android:text="AED 200.00"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/mainservice" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/activity_googlecards_card_imageview"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@+id/activity_googlecards_card_imageview"
        android:gravity="center"
        android:text="Specialist Name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#6945B2"
        android:textStyle="bold" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/activity_googlecards_card_imageview"
        android:layout_alignParentRight="true"
        android:focusable="false"
        android:focusableInTouchMode="false" />

    <ImageView
        android:id="@+id/activity_googlecards_card_imageview"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:scaleType="centerCrop"
        android:src="@drawable/list_dummy" />

</RelativeLayout>*
4

1 回答 1

0

如果列表行中有任何 clickalbe 项,则将执行其 click() 操作而不是 onItemClickListener。这里行项中有一个复选框,如果还想使用onItemClickListener,则必须使CheckBox在布局中不可聚焦,如下所示:

android:focusable="false"
android:focusableInTouchMode="false"
于 2013-08-20T05:29:52.383 回答