安卓的onClick方法 [英] Android onClick method
本文介绍了安卓的onClick方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在机器人项目中的两个的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;
}
});
和我有onther的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---
}
});
有没有什么解决方案呢?
Is there Any Solution for this?
推荐答案
您要拨打的第一个的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.
这篇关于安卓的onClick方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文