[Android]_ch11.8_FragmentDual元件2
package com.derek.ch30_fragmentdual;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
public class DetailActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent intent=getIntent();
Bundle bundle=intent.getExtras();
int position=bundle.getInt("position");
FragmentManager fm=getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
DetailFragment detailFragment=new DetailFragment(position);
ft.add(android.R.id.content, detailFragment);
ft.commit();
}
}
package com.derek.ch30_fragmentdual;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
public class DetailFragment extends Fragment{
int position;
TextView tv1,tv2;
ImageView iv;
public DetailFragment(int position){
this.position=position;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.detail_fragment, container,false);
tv1=(TextView)view.findViewById(R.id.textView1);
tv2=(TextView)view.findViewById(R.id.textView2);
iv=(ImageView)view.findViewById(R.id.imageView1);
iv.setImageResource(Resot.PARKS[position].getImageId());
tv1.setText(Resot.PARKS[position].getName());
tv2.setText(Resot.PARKS[position].getDescription());
return view;
}
}
沒有留言:
張貼留言