我有一个活动MyActivity,它扩展了MapActivity.在包含布局的.xml文件中,我只能包含MapView
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/trail_map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="key"
/>
Run Code Online (Sandbox Code Playgroud)
但是,我确实需要找到另一个位于另一个.xml文件中的视图.不幸的是,findViewById返回null.我怎样才能获得我想要的视图?
非常感谢!
San*_*ago 75
感谢您的评论,我明白您的意思,但我不想检查旧值.我只是想得到一个指向该视图的指针.
看着别人的代码,我刚刚找到了一个解决方法,你可以使用访问布局的根目录LayoutInflater.
代码如下,其中this是Activity:
final LayoutInflater factory = getLayoutInflater();
final View textEntryView = factory.inflate(R.layout.landmark_new_dialog, null);
landmarkEditNameView = (EditText) textEntryView.findViewById(R.id.landmark_name_dialog_edit);
Run Code Online (Sandbox Code Playgroud)
您需要获取this上下文的inflater ,通过inflate方法访问根视图,最后调用findViewById布局的根视图.
希望这对某人有用!再见
小智 5
我改变了我的活动但影响了.这是我的代码:
View layout = getLayoutInflater().inflate(R.layout.list_group,null);
try {
LinearLayout linearLayout = (LinearLayout) layout.findViewById(R.id.ldrawernav);
linearLayout.setBackgroundColor(Color.parseColor("#ffffff"));
}
catch (Exception e) {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
100438 次 |
| 最近记录: |