AndroidのGoogleマップレイアウトにピンポイントを配置し、2番目のレイアウトに移動して戻ってくると、ピンポイントが消えます
これは私の customPinpoint クラスです。
public class CustomPinpoint extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();
private Context c;
public CustomPinpoint(Drawable arg0) {
super(boundCenter(arg0));
}
public CustomPinpoint(Drawable m, Context context ) {
this(m);
c = context;
}
@Override
protected OverlayItem createItem(int arg0) {
// TODO Auto-generated method stub
return pinpoints.get(arg0);
}
@Override
public int size() {
// TODO Auto-generated method stub
return pinpoints.size();
}
public void insertPinpoint(OverlayItem item){
pinpoints.add(item);
this.populate();
}
}
これが私の主な活動です。
public class Main extends MapActivity {
private static final int REQUEST_CHOOSE_ADDRESS = 0;
private MapView map;
private Touchy t;
private List<Overlay> overlayList;
private long start;
private long stop;
private MyLocationOverlay compass;
private MapController controller;
private int x;
private int y;
private GeoPoint touchedPoint;
private Drawable d;
private Button pinPoint;
private EditText lat;
private EditText lon;
private boolean touched;
private Button dataInter;
private Calculate myRadius;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpView();
}
public void calculateRadiusClicked(View view){
Intent intent = new Intent(getBaseContext(), CalculateRadius.class);
startActivityForResult(intent, REQUEST_CHOOSE_ADDRESS);
}
private void setUpView() {
touched = false;
map = (MapView) findViewById(R.id.themap);
map.setBuiltInZoomControls(true);
t = new Touchy();
overlayList = map.getOverlays();
overlayList.add(t);
compass = new MyLocationOverlay(Main.this, map);
//overlayList.add(compass);
pinPoint = (Button) findViewById(R.id.button2);
dataInter = (Button) findViewById(R.id.button1);
lat = (EditText) findViewById(R.id.editlatitude);
lon = (EditText) findViewById(R.id.editLongitude);
d = getResources().getDrawable(R.drawable.ic_pinpoint);
myRadius = new Calculate();
pinPoint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawPinPoint();
}
});
}
public void drawPinPoint() {
String a = lat.getText().toString();
String b = lon.getText().toString();
if (!a.equals("") && !b.equals("") && touched == true) {
AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
builder.setMessage("Either click on the map or enter the latitude and longitude \nNot both at the same time");
builder.setCancelable(false);
builder.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
if (a.equals("") && b.equals("") && touched == false) {
AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
builder.setMessage("Enter latitude and longitude or click on the map");
builder.setCancelable(false);
builder.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
else if ((!a.equals("") || !b.equals("")) && touched == false) {
int xx = Integer.parseInt(a);
int yy = Integer.parseInt(b);
touchedPoint = new GeoPoint(xx, yy);
OverlayItem overlayItem = new OverlayItem(touchedPoint,
"What's up", "2nd String");
CustomPinpoint custom = new CustomPinpoint(d, Main.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
controller = map.getController();
controller.animateTo(touchedPoint);
map.invalidate();
//controller.setZoom(6);
} else if ((a.equals("") || b.equals("")) && touched == true) {
OverlayItem overlayItem = new OverlayItem(touchedPoint,
"What's up", "2nd String");
CustomPinpoint custom = new CustomPinpoint(d, Main.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
controller = map.getController();
controller.animateTo(touchedPoint);
//controller.setZoom(6);
}
if (!a.equals("") && !b.equals("") && touched == true) {
touched = false;
}
}
touched = false;
}
@Override
protected void onPause() {
compass.disableCompass();
super.onPause();
}
@Override
protected void onResume() {
compass.enableCompass();
super.onResume();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
class Touchy extends Overlay {
public boolean onTouchEvent(MotionEvent e, MapView m) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
start = e.getEventTime();
touched = true;
x = (int) e.getX();
y = (int) e.getY();
touchedPoint = map.getProjection().fromPixels(x, y);
}
if (e.getAction() == MotionEvent.ACTION_UP) {
stop = e.getEventTime();
}
return false;
}
}
}
これは私の 2 番目のアクティビティです public class CalculateRadius extends Activity { private Button calculateButton; プライベート EditText transmit_power_dbm; プライベート EditText SencitivityEdit; プライベート EditText TXEdit; プライベート EditText RXEdit; プライベート EditText 頻度編集; プライベート RadioGroup radioGroup; public Calculate cal = new Calculate(); プライベート EditText cellRadius; private static final int REQUEST_CHOOSE_ADDRESS = 0; プライベート メイン メイン;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculate_radius);
setUpView();
}
private void setUpView() {
calculateButton = (Button) findViewById(R.id.button1);
//main = new Main();
transmit_power_dbm = (EditText)findViewById(R.id.editTxPower);
sencitivityEdit = (EditText) findViewById(R.id.editRxSensitivity);
TXEdit = (EditText) findViewById(R.id.edittxHeight);
RXEdit = (EditText) findViewById(R.id.editRxHeight);
frequencyEdit = (EditText) findViewById(R.id.editFrequency);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
cellRadius = (EditText) findViewById(R.id.EditResult);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pathLoss();
}
});
}
public void plotTheRadius(View view){
Intent intent = new Intent(this, Main.class);
startActivityForResult(intent, REQUEST_CHOOSE_ADDRESS);
this.finish();
}
}