码迷,mamicode.com
首页 > 其他好文 > 详细

activity传值到fragment

时间:2016-01-22 02:39:42      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

public class MyFragment extends Fragment {   //FragmentActivity

public static MyFragment staticInstance = null;

public static MyFragment getInstance() {
if (staticInstance == null){
staticInstance = new MyFragment();
}
return staticInstance;
}
ImageView Touxiang,Lianxifangshi,Changyongdidian,Fuwuquyu,Yijianfankui,Changjianwenti;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.mygelin,container,false);
Touxiang=(ImageView)view.findViewById(R.id.Touxiang);   //头像
Bitmap bm = BitmapFactory.decodeFile("/sdcard/myheader/newpic.jpg"); //从本地取图片(在cdcard中获取) //
Touxiang .setImageBitmap(Util.toRoundBitmap(bm)); //设置Bitmap

Touxiang.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent=new Intent();
// intent.setClass(MyFragment.this, NMainActivity.class);
intent.setClass(getActivity(),NMainActivity.class);
startActivityForResult(intent,0); //这里使用startActivityForResult(intent,0); 从Fragment调到activity

}
});
public void onActivityResult(int requestCode, int resultCode, Intent data){  //这里的东西是activity结束时进行的,可以传值,可以进行初始化。
super.onActivityResult(requestCode, resultCode, data);
Bitmap bm = BitmapFactory.decodeFile("/sdcard/myheader/newpic.jpg"); //从本地取图片(在cdcard中获取) //
Touxiang .setImageBitmap(Util.toRoundBitmap(bm)); //设置Bitmap
}

activity传值到fragment

标签:

原文地址:http://www.cnblogs.com/to-creat/p/5149865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!