onChildClickListener无法在我的可扩展列表上运行。
子布局由代码自定义LinearLayout构成,并从xml中添加一些其他子视图。
对于xml,所有视图都设置为clickable = false。 扩展布局(其他视图的父布局)未设置为可点击的任何内容 - 明智的是因为它在代码中。
我相信我应该将自定义线性布局设置为可点击的false,但因为它在代码中我不确定这样做
这是我的getChildView方法:
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
String childText = (String) getChild(groupPosition, childPosition);
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = new ExtendedContentLinearLayout(context);
convertView).addViewToContentLayout(text);
ImageView leftImage = (ImageView) convertView.findViewById(R.id.child_left_image);
leftImage.setImageDrawable(context.getResources().getDrawable(R.drawable.folder_));
TextView childTextView = (TextView) convertView.findViewById(R.id.childTextView);
childTextView.setText(childText);
return convertView;
}
扩展LinearLayout:
public class ExtendedContentLinearLayout extends LinearLayout implements View.OnClickListener {
private View mTrigger;
private LinearLayout mContent;
public ExtendedContentLinearLayout(Context context) {
super(context);
mContent = new LinearLayout(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mTrigger = inflater.inflate(R.layout.nav_menu_board_expandable_children_outer, this, true);
this.addView(mContent);
mTrigger.setOnClickListener(this);
}
public ExtendedContentLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExtendedContentLinearLayout(Context context, AttributeSet attrs, int defStyle) {
this(context, attrs);
}
@Override
public void onClick(View v) {
App.disableTouchEventForDefaultDuration();
toggleVisibility();
}
public void addViewToContentLayout(View view) {
mContent.addView(view);
toggleVisibility();
}
private void toggleVisibility() {
if (mContent.getVisibility() == View.GONE) {
mContent.setVisibility(View.VISIBLE);
} else {
mContent.setVisibility(View.GONE);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mContent = null;
mTrigger = null;
}
}
子视图我添加到自定义布局的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:animateLayoutChanges="true"
android:layout_gravity="center_vertical"
android:clickable="false"
android:gravity="center_vertical"
android:id="@+id/triggerLayout"
android:background="@color/da_nav_drawer_dark"
android:layout_height="60dp">
<View
android:layout_width="4dp"
android:layout_height="match_parent"
android:background="@android:color/black" />
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="20dp"
android:clickable="false"
android:id="@+id/child_left_image"
android:layout_marginRight="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:textColor="@color/da_white"
android:id="@+id/childTextView" />
</LinearLayout>