アラートがポップアップしたときに、ボタンを追加せずに再度タッチしたときにアラートを閉じたいと思います。
マップピンタッチで
@Override
protected boolean onTap(int i) {
OverlayItem item = items.get(i);
dialog.setTitle(item.getSnippet());
dialog.setMessage(item.getTitle());
dialog.show();
return (true);
}
では、アラートまたはバックグラウンドの任意の場所にタッチして、それをなくすにはどうすればよいですか。
編集:追加されたコード
private class SitesOverlay extends ItemizedOverlay<CustomItem> {
private Drawable heart=null;
private List<CustomItem> items=new ArrayList<CustomItem>();
private PopupPanel panel=new PopupPanel(R.layout.popup);
public SitesOverlay() {
super(null);
heart=getMarker(R.drawable.heart_full);
JSONObject json;
JSONObject json2;
String resultURL = queryRESTurl("http://www.kickintheapp.com/api/maps393/json.json");
try {
json = new JSONObject(resultURL);
JSONArray nameArray = json.names();
JSONArray valArray;
valArray = json.toJSONArray(nameArray);
for (int i = 0; i < valArray.length(); i++)
{
Log.e(nameArray.getString(i), valArray.getString(i));
json2 = new JSONObject(valArray.getString(i));
JSONArray nameArray2 = json2.names();
JSONArray valArray2 = json2.toJSONArray(nameArray2);
for (int a = 0; a < valArray2.length(); a++)
{
// add to maps here
items.add(new CustomItem(getPoint(valArray2.getDouble(3),valArray2.getDouble(2)), valArray2.getString(1), valArray2.getString(0),getMarker(R.drawable.pin_yellow), heart));
Log.e(nameArray2.getString(a), valArray2.getString(a));
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
populate();
}
@Override
protected CustomItem createItem(int i) {
return(items.get(i));
}
@Override
public void draw(Canvas canvas, MapView mapView,
boolean shadow) {
super.draw(canvas, mapView, shadow);
}
@Override
protected boolean onTap(int i) {
OverlayItem item=getItem(i);
GeoPoint geo=item.getPoint();
Point pt=map.getProjection().toPixels(geo, null);
View view=panel.getView();
((TextView)view.findViewById(R.id.latitude))
.setText(item.getSnippet());
((TextView)view.findViewById(R.id.longitude))
.setText(item.getTitle());
panel.show(pt.y*2>map.getHeight());
return(true);
}
class PopupPanel {
View popup;
boolean isVisible=false;
PopupPanel(int layout) {
ViewGroup parent=(ViewGroup)map.getParent();
popup=getLayoutInflater().inflate(layout, parent, false);
popup.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
hide();
}
});
}
View getView() {
return(popup);
}
void show(boolean alignTop) {
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
if (alignTop) {
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp.setMargins(0, 20, 0, 0);
}
else {
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lp.setMargins(0, 0, 0, 60);
}
hide();
((ViewGroup)map.getParent()).addView(popup, lp);
isVisible=true;
}
void hide() {
if (isVisible) {
isVisible=false;
((ViewGroup)popup.getParent()).removeView(popup);
}
}
}