私LinearLayoutは 2 つを含む を持っていますRelativeLayouts。
XML コードは次のとおりです。
<LinearLayout
android:id="@+id/SaleSwithcBarView_navigation_bar_LinrearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<RelativeLayout
android:id="@+id/SaleSwithcBarView_users_created_bar_button_RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/SaleSwithcBarView_users_favorite_bar_button_RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
</LinearLayout>
今、clickListnerどのビューで (この 2 つRelativeLayoutsがクリックされたか) を検出しようとしています。次のようにしようとしました (Java コード):
navigationBar.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View navigationButton)
{
Toast.makeText(context, "hope here: " + navigationButton.getId(), Toast.LENGTH_LONG).show();
switch (navigationButton.getId())
{
case USER_CREATED_BUTTON_ID:
Toast.makeText(context, "here", Toast.LENGTH_LONG).show();
switchTodDisplay(USER_CREATED_BUTTON_ID + BINDER_OFFSET);
break;
case USER_FAVORITE_BUTTON_ID:
Toast.makeText(context, "or here", Toast.LENGTH_LONG).show();
switchTodDisplay(USER_CREATED_BUTTON_ID + BINDER_OFFSET);
break;
default:
break;
}
}
});
thenavigationBarは theLinearLayoutで、 the USER_CREATED_BUTTON_ID(it is final int) は leftRelativeLayoutのUSER_FAVORITE_BUTTON_IDid であり、 right の id ですRelativeLayout。私がプログラムで割り当てた両方のIDは、次のようになります。
userCreatedSalesBarButton.setId(USER_CREATED_BUTTON_ID);
userFavoriteSalesBarButton.setId(USER_FAVORITE_BUTTON_ID);
LinearLayoutでは、どの子ビューがクリックされたかをどのように検出できますか。clickListerinerfor eachを作成したくありませんRelativeLayout。
ありがとう