How can I get the height and width of an view of a view (which belongs to another activity) in the current activity. For example. There is a button in aactivity one and I have to get the attributes of teh button in activity two with the help of its id. (I have considered view because it can be ImageView, TextView, WebView or anything).
Here I am pasting the code which I have tried.
public class SecAct extends Activity{
ArrayList<Integer> butList1;
RelativeLayout help;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
help = (RelativeLayout)findViewById(R.id.helplay);
createWidgets();
}
private void createWidgets() {
// TODO Auto-generated method stub
butList1=MainActivity.butList;
int a=butList1.get(0);
View v=(View)(findViewById(a));
int width=v.getWidth();
int height=v.getHeight();
help.addView(v);
System.out.println("id is "+ width);
}
public void close(View v){
finish();
}
}
I am able to get the value of a but I am not able to get the attribute of the v(View) i.e., height, width or id e.t.c. I am getting an null pointer exception.