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();
performClick需要写在setOnClickListener的声明后面
android performClick使用说明
最新推荐文章于 2024-06-29 12:09:25 发布