0
フラグメント内にボタンがあります。 moneyBtn
が見つかりました。val button:Button? = view?.findViewById(R.id.moneyBtn) as Button?
?
を使用しました。これは、IDEが構文エラーを引き起こすためです。フラグメントボタンonClickListenerが実行されていません
button
は現在、setOnClickListenerを使用している:
button?.setOnClickListener {
moneyGetten()
mEditor.putInt("money", money++)
mEditor.commit()
moneyGetten()
Log.d("BUTTON CLICKED", "!")
}
私の理論を:findViewは?
はOnClickListenerを「保護」され、null
で応答しますので、ビューは、いくつかの理由が見つかりません。ここで
は私のXMLです:どういうわけか
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.fosefx.clickergame.Generator">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/plus1label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="135dp"
android:text="+1"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
<Button
android:id="@+id/moneyBtn"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="67dp"
android:text="CLICK ME" />
</RelativeLayout>
</FrameLayout>
デバッガーで理論をテストする必要があります。あるいは、これらの変数の値を記録することによってさえも。 – zsmb13
valよりもむしろvarとしてみてください。 –