在这部分放置什么,以便按钮可以获得第二个按钮的属性? [英] What to put on this part so the button can get the properties of the second button?

查看:64
本文介绍了在这部分放置什么,以便按钮可以获得第二个按钮的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class Activ2 extends Activity implements OnClickListener {
	
	ImageButton butt1,butt2,butt3;
	TextView textview1;
	int buttonHeight =1, buttonWidth =1;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_activ2);
        butt1 = (ImageButton) findViewById(R.id.Butt1);
        textview1 = (TextView)findViewById(R.id.textView1);
        butt1.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				
"What to put on this part so the button can get the properties of the second button?"
 
			}
        });

推荐答案

这是一个闭包,所以butt2和butt3在范围内,如果你在设置butt1的事件处理程序之前分配它们,你可以按名称引用它们,即< br $> b $ b

That's a closure so butt2 and butt3 are in scope, if you assign them before setting butt1's event handler you can just refer to them by name, i.e.

butt1 = (ImageButton) findViewById(R.id.Butt1);
butt2 = (ImageButton) findViewById(R.id.Butt2);
butt1.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
    butt2.Text = "whatever";
  }
});


这篇关于在这部分放置什么,以便按钮可以获得第二个按钮的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆