어떻게 OnClick 이벤트 버튼을 프로그래밍합니까?
-
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