Estou a receber null da minha chamada findViewById, e não consigo perceber porque. O código em baixo é relativo a uma Activity
no meu programa:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.dashboard);
getLayoutInflater().inflate(R.layout.activity_cpc_select, frameLayout);
TreeNode root = TreeNode.root();
TreeNode parent = new TreeNode("MyParentNode");
TreeNode child0 = new TreeNode("ChildNode0");
TreeNode child1 = new TreeNode("ChildNode1");
parent.addChildren(child0, child1);
root.addChild(parent);
AndroidTreeView tView = new AndroidTreeView(this, root);
FrameLayout view= (FrameLayout) findViewById(R.id.cpc_tree_view);
view.addView(tView.getView());
}
O meu layout está definido assim:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/cpc_tree_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</FrameLayout>
Activity#findViewById()
tem de indicar que a Activity usa o layout onde está esse FrameLayout através desetContentView()
.