我是 Fragments 的新手,我正在努力解决这个问题。下面是我的代码。为了它。当我运行我的应用程序时,我没有任何错误消息,但我没有得到输出
MainActivity.java
public class MainActivity extends FragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
MyFragments.java
public class MyFragments extends Fragment {
public MyFragments() {
// TODO Auto-generated constructor stub
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
return view;
}
}
fragment_one.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" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_One"
android:name="com.benchmark.fragmentsdemo.MyFragments"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<fragment
android:id="@+id/fragment_two"
android:name="com.benchmark.fragmentsdemo.MyFragments"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
</LinearLayout>
请任何人帮助我