在项目单击侦听器不在列表视图中工作

时间:2012-11-29 10:46:54

标签: android

您好,在我的应用中,我想点击列表中的项目来执行某些功能。

这是列表项的xml。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="#FFFFFF"
    android:layout_marginTop="20dp"
    android:focusableInTouchMode="true" android:focusable="true">

    <TableLayout android:layout_width="fill_parent" android:layout_marginTop="10dp"
        android:layout_height="wrap_content" android:id="@+checklistitem/itemrow">
        <TableRow android:id="@+checklistitem/tr"> 
            <TextView android:id="@+checklistitem/texthead"
            android:textStyle="bold"
            android:visibility="gone" android:layout_marginLeft="10dp"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:paddingRight="0dp" android:maxLines="2" android:textSize="16dp"
                android:text="Towel Rack: 2 hand towels,2 wash clothes"
                android:background="#000000" android:textColor="#ffffff"
                android:layout_centerVertical="true"  />

            <TextView android:id="@+checklistitem/textSeparator"
            android:visibility="gone" android:layout_marginLeft="10dp"
                android:layout_width="240dp" android:layout_height="fill_parent"
                android:paddingRight="0dp" android:maxLines="2" android:textSize="16dp"
                android:text=""
                android:background="#000000" android:textColor="#ffffff"
                android:layout_centerVertical="true"  />


            <TextView android:layout_marginLeft="5dp"
                android:id="@+checklistitem/inspectionvalue" android:visibility="visible"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textColor="#006699" android:text="01"
                android:layout_alignParentRight="true" android:layout_marginRight="8dp"
                android:layout_centerVertical="true" />
        </TableRow>
    </TableLayout>

</RelativeLayout>

这里是我使用适配器列表的代码

checklistview.setOnItemClickListener(this);


        CheckListAdapterForAtt checkAdapter = new CheckListAdapterForAtt(this.getApplicationContext(), checkListRowDataArr, R.layout.checklist_row);

但有些项目点击列表器对我不起作用???

2 个答案:

答案 0 :(得分:1)

在要单击的XML行布局中添加以下内容

android:clickable="false"
android:focusable="false" 

Onclick听众喜欢以下

mList.setOnItemClickListener(new OnItemClickListener() {

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

            }
        });

答案 1 :(得分:0)

尝试这样:

 listView.setOnItemClickListener(new OnItemClickListener() {

        private void OnItemSelected() {

        }

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            if(arg2 == 0)
            {

            }

            if(arg2 == 1)
            {

            }
相关问题