所以我有一个片段中的以下ImageButton: 和下面的片段Activity.txt class Home : Fragment() { override public fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view: View? = inflater.inflate(R.layout.fragment_home, container, false) val moneyButton: ImageButton = view?.findViewById(R.id.moneyBtn) as ImageButton val result = MyAppApplication() var money = result.money moneyButton.setOnClickListener(View.OnClickListener { Toast.makeText(activity, “TESTING BUTTON CLICK 1”, Toast.LENGTH_SHORT).show() }) return view } 我也尝试使用“正常”Kotline setOnClickListener moneyButton.setOnClickListener […]
所以我有一个片段中的以下ImageButton: <ImageButton android:id="@+id/moneyBtn" style="@android:style/Widget.Holo.Light.ImageButton" android:layout_width="250dp" android:layout_height="250dp" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:scaleType="fitCenter" android:adjustViewBounds="true" android:src="@drawable/monkey" android:background="@null"/> 和下面的片段Activity.txt class Home : Fragment() { override public fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view: View? = inflater.inflate(R.layout.fragment_home, container, false) val moneyButton: ImageButton = view?.findViewById(R.id.moneyBtn) as ImageButton val result = MyAppApplication() var money = result.money moneyButton.setOnClickListener(View.OnClickListener { Toast.makeText(activity, "TESTING […]