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

FragMent-实例创建

时间:2015-03-08 14:14:08      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

一,定义一个fragment


 

public View onCreateView(LayoutInflater inflater,
                ViewGroup container,  Bundle savedInstanceState) {
            mView = inflater.inflate(R.layout.detail_dialog, container, false);
            if (mView != null) {
                mTitleView = (TextView) mView.findViewById(R.id.title);
                mTimeView = (TextView) mView.findViewById(R.id.time);
                mDurationView = (TextView) mView.findViewById(R.id.duration);
                mPathView = (TextView) mView.findViewById(R.id.path);
                mFileSizeView = (TextView) mView.findViewById(R.id.filesize);

                mTitleView.setText(getArguments().getString("mTitle",""));
                android.util.Log.e("zhangshuli", "+++++++"+getArguments().getString("mTitle",""));
                mPathView.setText(getArguments().getString("mData",""));
                mDurationView.setText(getArguments().getString("mDuration",""));
                 //   +MtkUtils.stringForTime(mHolder.mDuration));
                mTimeView.setText(getArguments().getString("mDateTaken",""));
                    //+MtkUtils.localTime(mHolder.mDateTaken));
                mFileSizeView.setText(getArguments().getString("mFileSize",""));
                //+Formatter.formatFileSize(mContext, mHolder.mFileSize));
                //  setButton(BTN_OK, mContext.getString(android.R.string.ok), this);
            } else {
                return super.onCreateView(inflater, container, savedInstanceState);
            }
     btn = (Button)mView.findViewById(R.id.detail_btn);
     btn.setOnClickListener(new View.OnClickListener() {

     @Override
     public void onClick(View arg0) {
    // TODO Auto-generated method stub
    if (getActivity() instanceof CancelClickListener) 
    { 
    ((CancelClickListener) getActivity()).cancelListen(); 
    } 

    }
    });
    return mView;

    }
    
// End of Vanzo: zhangshuli
public interface CancelClickListener{
void listen();
}

 

  
activity 中实现引用

 

private void showDetail(final ViewHolder mHolder) {
                String mTitle =""+mHolder.mTitle;
                String mData=""+mHolder.mData;
                String mDuration =""+MtkUtils.stringForTime(mHolder.mDuration);
                String mDateTaken =""+MtkUtils.localTime(mHolder.mDateTaken);
                String mFileSize =""+Formatter.formatFileSize(this, mHolder.mFileSize);
                mFragment=new DetailFragment();
                mBundle =new Bundle();
                fmFragmentManager=getFragmentManager();
                mBundle.putString("mTitle", mTitle);
                mBundle.putString("mData", mData);
                mBundle.putString("mDuration", mDuration);
                mBundle.putString("mDateTaken", mDateTaken);
                mBundle.putString("mFileSize", mFileSize);
                android.util.Log.e("zhangshuli", "======"+mFileSize);
                mFragment.setArguments(mBundle);
                fmFragmentManager.beginTransaction().replace(R.id.main,mFragment).commit();
    }   

 

FragMent-实例创建

标签:

原文地址:http://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_fragmeng_150308143.html

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