2013-08-20 42 views
0

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

我的列表视图听众,

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; 
} 

的RowLayout 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>* 
+0

你是否已将所有ListRow视图设置为'android:Focusable = fale' ..? – SilentKiller

+0

据我所知,这是不可能的。 – SKK

+0

@SilentKiller无法正常工作.. –

回答

0

如果有任何clickalbe项目列表行的click()操作将发生,而不是onItemClickListener。在这里,你必须在该行项的复选框,如果你仍然想使用onItemClickListener,你必须将CheckBox如下布局不可作为焦点:

android:focusable="false" 
android:focusableInTouchMode="false" 
+0

让我看看你的xml – Suji

+0

@Basim Sherif,删除focusable:false RelativeLayout – Suji

1

请参阅此链接。这篇文章给你最好的想法。 Link

+0

这是不同于我的评论? –