没有查看发现ID 0x7f090005 [英] No view found for id 0x7f090005
问题描述
我开始构建一个简单的Android应用程序,所以当我preSS我的视频按钮,它调用它包含了视频播放的片段,但我总是因为:没有查看发现ID 0x7f090005 ...
I'm starting to build a simple Android app so when I press my video button it calls a fragment which contains the video player, but I'm always getting: No view found for id 0x7f090005...
我不知道,如果你给我一只手搞清楚什么是错在我写的code。
I wonder if you give me a hand by figuring out what is wrong in the code that I'm writing.
下面是我的MainActivity.java文件:
Here is my MainActivity.java file:
public class MainActivity extends Activity {
private Button mVideoButton;
Fragment fragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mVideoButton = (Button)findViewById(R.id.videoButton);
// Video Button
mVideoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
FragmentVideo sf = new FragmentVideo();
ft.add(R.id.fragmentVideo, sf);
ft.commit();
}
});
}
}
然后,我有我的main_activity.xml:
Then I have my main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activityStart" >
<ImageView
android:src="@drawable/armstrong_on_moon"
android:contentDescription="@string/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:layout_weight="1" />
<TableRow
android:gravity="center|bottom"
android:layout_weight="0">
<Button
android:id="@+id/videoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/video" />
</TableRow>
接下来,我FragmentVideo.java类:
Next, my FragmentVideo.java class:
public class FragmentVideo extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState ){
View v = inflater.inflate(R.layout.fragment_video, parent, false);
return v;
}
}
而在去年,该fragment_video.xml
And at last, the fragment_video.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/fragmentVideo" >
<VideoView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<ProgressBar
android:id="@+id/prog"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center" />
</LinearLayout>
请让我知道,如果我做错了什么,或者如果我失去了一些东西,因为我能看到问题的规定。
Please let me know if I'm doing something wrong or if I'm missing something as I can see where the issue lays.
非常感谢提前任何帮助。
Thanks very much for any help in advance.
EGMWEB
推荐答案
在 ft.add()
整型参数指的是容器要添加片段
;您要添加片段
到片段
的自己的布局(Android不找到查看
,因为它不充气的是,如果它确实会引发和异常
在这种情况下,你不能添加片段
来自己的布局)。要替换 R.id.fragmentVideo
与 R.id.activityStart
添加片段
的电流 TableLayout
这是已经膨胀 main_activity
布局的一部分。
On ft.add()
the int parameter refers to the container to which you want to add the Fragment
; you are trying to add the Fragment
to the Fragment
's own layout (Android doesn't find the View
because it is not inflated yet, if it did it will throw and Exception
in this case; you cannot add a Fragment
to its own layout). You want to replace R.id.fragmentVideo
with R.id.activityStart
to add the Fragment
to the current TableLayout
that is part of the already inflated main_activity
layout
这篇关于没有查看发现ID 0x7f090005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!