Android onClick 方法 [英] Android onClick method
本文介绍了Android onClick 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在android项目中有两个onclick方法
I have two onclick method in android project
clr=(Button)findViewById(R.id.Button01);
clr.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
tv1.setText("CLR");
et1.setText("");
refrigerant = "";
pres = "";
temperature = "";
superheat_oda = 0;
sub_cool = 0;
}
});
而且我有 onClick 方法,我必须直接调用该方法
And i have onther onClick method in which i have to call that method directly
prs=(Button)findViewById(R.id.Button02);
prs.setOnClickListener(new OnClickListener() {
----- I have to call that method---
}
});
有什么解决办法吗?
推荐答案
您想从第二个调用第一个 onClick
吗?只需在单独的方法中提取第一个 onClick 的内容,然后从每个 onClick
调用该方法.
You want to call the first onClick
from the second? Just extract the contents of your first onClick in a separate method and call that method from each onClick
.
根据 st0le 的评论,您可以通过调用 clr.performClick()
来做您想做的事.(不知道.)不过,将其提取到单独的方法中似乎更简洁.
As per st0le's comment, you can do what you want by calling clr.performClick()
. (Didn't know that.) Still, extracting it into a separate method seems cleaner.
这篇关于Android onClick 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文