android performClick使用

2022-09-13 10:12:02 浏览数 (2)

大家好,又见面了,我是你们的朋友全栈君。

performClick 是使用代码主动去调用控件的点击事件(模拟人手去触摸控件)

—————————————–

boolean android.view.View.performClick()

Call this view’s OnClickListener, if it is defined.

Returns:

True there was an assigned OnClickListener that was called, false otherwise is returned.

———————————————

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_my);

btn1 = (Button) findViewById(R.id.button1);

tv1 = (TextView) findViewById(R.id.textView1);

btn1.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

tv1.setText(“已经被点击过了”);

}

});

// 模拟点击事件

btn1.performClick();

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148978.html原文链接:https://javaforall.cn

0 人点赞