我在获取已单击视图的哪一部分的信息时遇到问题。我将子行项目定义为:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/child_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/row_height"
android:background="@color/app_white" >
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/row_margin"
android:button="@drawable/checkbox_states"
android:focusable="false" />
</RelativeLayout>
<View
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:background="@android:color/transparent"
android:focusable="false" />
</LinearLayout>
在 Activity 我需要定义 onChildClick
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
Log.e(LOGTAG, "onChildClick: v.getTag: " + v.getTag() + " groupPos: " + groupPosition
+ " childPosition: " + childPosition + " rowId: " + id);
if (v instanceof LinearLayout) {
View view = ((LinearLayout) v).getChildAt(1);
if (view != null) {
if (view.getTag() != null) {
Log.e(LOGTAG, "onChildClick: view.isSelected: "+view.isSelected());
Log.e(LOGTAG, "onChildClick: view.isPressed: "+view.isPressed());
Log.e(LOGTAG, "onChildClick: view.getTag: " + view.getTag());
return true;
}
}
}
正如我所看到的,视图始终是 LinearLayout。如果单击视图或相对布局,我如何获取信息?