我在fragment
中有一个my activity
。我正在尝试使RelativeLayout
中的fragment
有趣,但是当我单击它不起作用时,什么也没发生。
activity_main.xml:
<RelativeLayout
android:padding="5.0dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15.0dip"
android:layout_marginTop="15.0dip"
android:layout_marginRight="15.0dip"
android:layout_marginBottom="5.0dip"
android:layout_below="@+id/header2">
<FrameLayout
android:id="@+id/frameCoin"
android:background="@color/colorTransparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
fragment_main.xml:
<RelativeLayout
android:id="@+id/relative500coin"
android:background="@drawable/buttons_bg"
android:padding="5.0sp"
android:layout_width="fill_parent"
android:layout_height="70.0dip"
android:layout_marginBottom="10.0dip"
android:focusable="true">
<ImageView
android:id="@+id/coin500Image"
android:layout_width="38.0dip"
android:layout_height="38.0dip"
android:layout_marginStart="16.0dip"
android:src="@drawable/coin_count_image"
android:tint="@color/colorWhite"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="38.0dip"
android:layout_toEndOf="@+id/coin500Image"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true">
<TextView
android:textSize="20.0sp"
android:textStyle="bold"
android:textColor="#ffffffff"
android:paddingLeft="15.0dip"
android:paddingRight="15.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0.0dip"
android:text="@string/coin_500"
android:layout_alignParentTop="true"
tools:ignore="RelativeOverlap" />
<TextView
android:textSize="12sp"
android:textColor="#ffffffff"
android:paddingLeft="15.0dip"
android:paddingRight="15.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/coin_500_text"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/coin_500_price"
android:textSize="25sp"
android:textStyle="bold"
android:layout_marginEnd="10sp"
android:textColor="@color/colorWhite"
android:tint="#ffffffff"
android:layout_alignParentEnd="true"
tools:ignore="RelativeOverlap" />
</RelativeLayout>
</RelativeLayout>
Fragment.java:
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_main, container, false);
RelativeLayout relative500coin = view.findViewById(R.id.relative500coin);
relative500coin.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
bp.consumePurchase("coin_500");
bp.purchase(getActivity(), "coin_500");
}
});
return view;
}
这是我在xml和java中所做的所有代码。但是我找不到任何错误。任何人都知道这里有什么问题吗?非常感谢。
答案 0 :(得分:0)
private void navigateToViewDetailProgress(View view) {
RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.relative_layout);
rl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
(Do your onclick action here)
}
}
}
在Fragment的onResume中调用上述函数。确保将rootview作为函数参数传递。