2012-11-29 46 views
0

嗨在我的應用程序我想要做一些功能點擊列表中的項目。Onitem單擊列表工具不能在列表視圖

這是列表項的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); 

的代碼,但一些如何產品Click聽者不爲我工作???

+0

相同的問題:定義「不起作用' – njzk2

+0

我有公共無效onItemClick(AdapterView arg0,查看arg1,int arg2,long arg3){}這種方法,但點擊該項目的控制不會出現在這? –

回答

1

添加在您需要點擊

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

的onclick聽衆像下面

mList.setOnItemClickListener(new OnItemClickListener() { 

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

      } 
     }); 
0

嘗試這樣的XML列布局如下:

listView.setOnItemClickListener(new OnItemClickListener() { 

     private void OnItemSelected() { 

     } 

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

      } 

      if(arg2 == 1) 
      { 

      }