安卓作业之跳转2
首先依旧是最基础的xml代码
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:id="@+id/show">
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btnshow"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:id="@+id/btnshow"
android:onClick="onClick"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:orientation="vertical"
android:id="@+id/txtshow2">
</LinearLayout>
然后是java
View view = inflater.inflate(R.layout.fragment_biaoti, container, false);
TextView txtContent = (TextView) view.findViewById(R.id.biaoti_show);
txtContent.setText(content);
return view;
public void setContent(String content) {
this.content = content;
}
静态
FragmentManager manager = getFragmentManager();
transaction = manager.beginTransaction();
biaotiFragment.setContent("This is first fragment");
transaction.add(R.id.show, biaotiFragment);
transaction.commit();
动态代码
btshow.setOnClickListener(new View.OnClickListener()
{