2011-11-22 88 views
0

在Android中,您可以使用findViewById()来查找动态添加的控件吗?查找Android动态控件

添加在一个类似的方式:

Button btn=new Button(this); 
btn.setId(1); 
btn.setBackgroundResource(R.drawable.image); 
Relativelayout.addView(btn); 

感谢

+0

是你可以....你需要调用Relativelayout.findViewById(如果变量的名字是Relativelayout) – Selvin

+0

这很有用,谢谢 – user614143

回答

0

您可以使用此:

//view.findViewById(id); here pass the same id which you have set earlier for a particular view, while adding view to layout/view. 
Button btn = (Button) relativeLayout.findViewById(1); 
+0

太棒了,谢谢 – user614143