سؤال

الهدف:أن يكون بيان إذا تنفيذ حدث أونكليك من خلال التعليمات البرمجية.

لدي حاليا هذا الزر في شمل.

<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(); ولكن أحصل على

لا يمكن استدعاء بيرفورمكليك () على النوع البدائي كثافة العمليات

لدي الشرطي أدناه لتكرار إذا كان العد أقل من 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();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top