在您的BaseAdapter
overridegetView
中,获取对每个孩子的引用并为每个孩子设置onClickLister
,每次被getView
调用时,样本:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView = inflater.inflate(R.layout.layout, parent,false);
}
final MyClass item = (MyClass)getItem(position);
View child1 = convertView.findViewById(R.id.child1);
child1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("tag", "child1 from item "+ position +" , is clicked.");
}
});
View child2 = convertView.findViewById(R.id.child2);
child2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("tag", "child2 from item "+ position +" , is clicked.");
}
});
return convertView;}
对于 Swipe,扩展您的LinearLayout
并覆盖onInterceptTouchEvent
其中,并将其传递给GestureDetector
并处理其上的滚动。有关GestureDetector
和 Swipe 的更多信息,请查看 GoogleGestureDetector
和SimpleOnGestureListener
示例。