我有带有自定义 itemizedoverlay 的地图视图。我在信息窗口放了两个按钮。我的问题是我在神经按钮上的代码对吗?我把意图和烤面包,但它没有显示。这是我的代码。谢谢。
public class MyItemizedOverlay extends ItemizedOverlay {
private ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
private Drawable marker;
private Context mContext;
Route route;
MapView mapView;
private ArrayList<Lokasi> list_fasilitas = new ArrayList<Lokasi>();
public MyItemizedOverlay(Drawable defaultMarker) {
super(defaultMarker);
items = new ArrayList(); //mbuh
marker = defaultMarker;
}
public MyItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
@Override
protected OverlayItem createItem(int index) {
return (OverlayItem) items.get(index);
}
@Override
public int size() {
return items.size();
}
/*
* (non-Javadoc)
*
* @see
* com.google.android.maps.ItemizedOverlay#draw(android.graphics.Canvas,
* com.google.android.maps.MapView, boolean)
*/
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
// boundCenterBottom(marker);
}
public void addItem(OverlayItem item) {
items.add(item);
populate();
}
//@Override
protected boolean onTap(int index) {
OverlayItem item = items.get(0);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.setNeutralButton("location", new OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1) {
for (int i = 0; i < list_fasilitas.size(); i++) {
try
{
String nama = list_fasilitas.get(i).nama_rs;
Toast.makeText(mContext, "lala:"+nama, Toast.LENGTH_SHORT).show();
initializeData(nama);
Intent intent = new Intent(mContext, detailactivity.class);
mContext.startActivity(intent);
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
}
}
});
dialog.setPositiveButton("Close", new OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
});
dialog.show();
return true;
}
private void initializeData(String namars) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("namars",namars));
sendData(nameValuePairs);
}
private void sendData(ArrayList<NameValuePair> data) {
// TODO Auto-generated method stub
// 1) Connect via HTTP. 2) Encode data. 3) Send data.
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.199.1/RS/generate_detailrs.php");
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = httpclient.execute(httppost);
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
}
}
这是我的神经按钮代码:
dialog.setNeutralButton("location", new OnClickListener()
{
public void onClick(DialogInterface arg0, int arg1) {
for (int i = 0; i < list_fasilitas.size(); i++) {
try
{
String nama = list_fasilitas.get(i).nama_rs;
Toast.makeText(mContext, "lala:"+nama, Toast.LENGTH_SHORT).show();
initializeData(nama);
Intent intent = new Intent(mContext, detailactivity.class);
mContext.startActivity(intent);
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
}
}
});