Activity传数据给fragment
来源:互联网 发布:ipad能开淘宝店吗 编辑:程序博客网 时间:2024/06/07 09:35
1、
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
/>
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.FrameLayout;
public class MainActivity extends FragmentActivity {
FrameLayout content_frame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
content_frame = (FrameLayout) findViewById(R.id.content_frame);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new FrameLayoutFragment("传参数"))
.commit();
}
}
2、
<?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/frag_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是fragment" />
</LinearLayout>
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class FrameLayoutFragment extends Fragment{
View view;
TextView frag_text;
String aaaa;
public FrameLayoutFragment(String string) {
aaaa = string;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.frame_layout, container, false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
initView();
super.onActivityCreated(savedInstanceState);
}
private void initView() {
frag_text = (TextView) view.findViewById(R.id.frag_text);
frag_text.setText(aaaa + "aaa");
}
}
- Activity传数据给fragment
- activity给fragment传递数据
- Activity给自己下面其中一个Fragment传数据
- Activity传值给Fragment
- fragment传值给Activity
- fragment 传值给activity
- Activity或Fragment传值给Fragment
- Activity,Fragment数据回传
- fragment传值给activity:接口
- Activity给Fragment传参
- 将一个类(或Fragment)中的数据传递给另一个activity(或Fragment)
- Activity传递Binder给Fragment
- EventBus:Activity给Fragment传值
- 从Fragment中传数据到Activity
- Activity通过接口向fragment传数据
- Andriod Fragment---给Activity添加一个Fragment
- Andriod Fragment---给Activity添加一个Fragment
- Andriod Fragment---给Activity添加一个Fragment
- Network
- Linux
- Network
- Python
- Network
- Activity传数据给fragment
- Java
- C语言指针导学(3)——指针与数组的“爱恨情仇”
- Eclipse Android 安装详解
- Spring JavaMail发送邮件
- Testing
- 如何在 Ubuntu 中关闭触摸板
- Linux
- java学习【JDBC入门】