ボタンオンクリックイベントをどのようにコーディングしますか?
-
11-12-2019 - |
質問
AIM:IFステートメントを実行するには、コードを通じてOnClickイベントを実行します。
現在このボタンをXMLにしています。
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set Call"
android:onClick="makeCall"/>
.
R.id.button1.performClick();
を試しましたが、
プリミティブ型int でperformclick()を呼び出すことができません
カウントが5未満の場合は、以下の条件付きがあります。
.public void onActivityResult(int requestCode, int resultCode, Intent data) { int count=0; if (count <= 5) { //make call R.id.button1.performClick(); count++; Toast toast=Toast.makeText(this, "Count is currently" + count++ + ", repeating", Toast.LENGTH_LONG); toast.show(); } else { // Toast Popup when call set button pressed Toast toast=Toast.makeText(this, "Call count complete, ending method" , Toast.LENGTH_LONG); toast.show(); count++; } }
解決
ボタンを参照する必要があります。その後、それを使用できます。
Button button1 = yourview.findViewById(r.id.button1);
button1.performClick();
. 所属していません StackOverflow