2
1)如何從ViewPagerActivity(其延伸地圖)值發送到PagerAdapter即lat和長時間?如何更新PagerAdapter TextView中(使用後內部instantiateItem充氣)
2)如何更新TextView的在PagerAdapter
附:我嘗試getItemPosition
並返回POSITION_NONE,但它不工作
ViewPagerActivity
public class ViewPagerActivity extends MapActivity {
private ViewPagerAdapter adapter;
private ViewPager pager;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new ViewPagerAdapter(this);
pager = (ViewPager) findViewById(R.id.viewpager);
TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.indicator);
pager.setAdapter(adapter);
indicator.setViewPager(pager);
// Brief
updateWithNewLocation(location);
}
private void updateWithNewLocation(Location location) {
String latLongString;
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
} else {
latLongString = "No location found";
}
// Is is possible to set text here
// myLocationText = (TextView)findViewById(R.id.myLocationText);
// myLocationText.setText("Your Current Position is:\n"+latLongString);
}
}
ViewPagerAdapter
public class ViewPagerAdapter extends PagerAdapter implements TitleProvider {
private final Context context;
private MapView mapView;
private MapController mapController;
private TextView myLocationText;
private View view;
public ViewPagerAdapter(Context context) {
}
private static String[] titles = new String[] { "Page1", "Map" };
@Override
public String getTitle(int position) {
return titles[position];
}
@Override
public int getCount() {
return titles.length;
}
@Override
public Object instantiateItem(View pager, final int position) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (position == 0) {
view = inflater.inflate(R.layout.whereami, null);
((ViewPager) pager).addView(view, 0);
// myLocationText =
// (TextView)view.findViewById(R.id.myLocationText);
// myLocationText.setText("Your Current Position is:\n"+mylocation);
}
if (position == 1) {
view = inflater.inflate(R.layout.my_map_activity, null);
((ViewPager) pager).addView(view, 0);
mapView = (MapView) view.findViewById(R.id.mapview);
mapController = mapView.getController();
mapController.setZoom(14);
}
return view;
}
@Override
public void destroyItem(View pager, int position, Object view) {
((ViewPager) pager).removeView((View) view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
@Override
public void finishUpdate(View view) {
}
@Override
public void restoreState(Parcelable p, ClassLoader c) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View view) {
}
}