标签:
一,定义一个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(); }
标签:
原文地址:http://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_fragmeng_150308143.html