Android ch11 7 FragmentDual元件1
package com.derek.ch30_fragmentdual;
import java.util.ArrayList;
import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MasterFragment extends ListFragment{
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
ArrayList<String> parkName=new ArrayList<String>();
for(Park park:Resot.PARKS){
parkName.add(park.getName());
}
ArrayAdapter<String> AA=new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_activated_1,parkName);
setListAdapter(AA);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
showDetail(position);
}
public void showDetail(int position){
Intent intent=new Intent();
intent.setClass(getActivity(), DetailActivity.class);
intent.putExtra("position", position);
startActivity(intent);
}
}
package com.derek.ch30_fragmentdual;
import android.app.Activity;
import android.os.Bundle;
public class DetailActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
}
package com.derek.ch30_fragmentdual;
import android.R.integer;
public class Park {
String name;
int imageId;
String description;
public Park(String name,int imageId,String description){
this.name=name;
this.imageId=imageId;
this.description=description;
}
public String getName(){
return name;
}
public String getDescription(){
return description;
}
public int getImageId(){
return imageId;
}
}
package com.derek.ch30_fragmentdual;
public final class Resot {
public static final Park PARKS[]={
new Park("陽明山國家公園", R.drawable.yangmingshan,"陽明山國家公園前身為日治時期成立之大屯國立公園,1985年9月16日成立管理處。位於台北市近郊,行政區域包括同市北投區、士林區,新北市的萬里區、金山區、三芝區、淡水區一帶;地理上則屬於大屯火山彙區域。"),
new Park("玉山國家公園", R.drawable.yushan, "玉山國家公園是台灣第2座國家公園,1985年4月10日成立管理處,面積10萬5,490公頃,屬一典型高山國家公園。"),
new Park("太魯閣國家公園", R.drawable.taroko, "太魯閣國家公園前身為日治時期成立之次高太魯閣國立公園,1986年11月28日成立管理處。位於台灣東部,地跨花蓮縣、台中市、南投縣三個行政區。"),
new Park("墾丁國家公園", R.drawable.kenting, "墾丁國家公園是台灣第1座成立的國家公園,1984年1月1日成立管理處,三面臨海,為我國少數同時涵蓋陸域與海域的國家公園之一,海域面積15206.09公頃、陸域面積18083.50公頃,合計共33,289.59公頃。")
};
}
沒有留言:
張貼留言