- <pre class="java" name="code" snippet_file_name="blog_20170413_1_8084624" code_snippet_id="2330596"> 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) {
- <span style="white-space: pre;"> </span>super.onCreate(savedInstanceState);
- <span style="white-space: pre;"> </span>setContentView(R.layout.activity_my);
- <span style="white-space: pre;"> </span>btn1 = (Button) findViewById(R.id.button1);
- <span style="white-space: pre;"> </span>tv1 = (TextView) findViewById(R.id.textView1);
- <span style="white-space: pre;"> </span>btn1.setOnClickListener(new OnClickListener() {
- <span style="white-space: pre;"> </span>@Override
- <span style="white-space: pre;"> </span>public void onClick(View v) {
- <span style="white-space: pre;"> </span>tv1.setText("已经被点击过了");
- <span style="white-space: pre;"> </span>}
- <span style="white-space: pre;"> </span>});</pre><pre class="java" name="code" snippet_file_name="blog_20170413_2_2480253" code_snippet_id="2330596"><pre class="java" name="code" snippet_file_name="blog_20170413_2_2480253" code_snippet_id="2330596"><span style="white-space: pre;"> </span>btn1.performClick();</pre>}
- <pre></pre>
- <pre class="java" name="code" snippet_file_name="blog_20170413_3_7605447" code_snippet_id="2330596"><span style="color: rgb(51, 51, 51); font-family: Tahoma; font-size: 18px;">performClick需要写在<span style="color: rgb(51, 51, 51); font-family: Tahoma; font-size: 18px;">setOnClickListener的声明后面</span></span>
- </pre>
- <pre></pre>
- </pre>
android performClick使用说明
最新推荐文章于 2025-01-21 09:00:00 发布