这是我在 google maps android api v2 中添加标记的代码。我的问题是我无法从我的 EditText 片段中获取字符串值。代码 .getText().toString() 无法获取字符串值,只发送空值。请帮我。
googlemap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(final LatLng latlng) {
LayoutInflater li = LayoutInflater.from(context);
final View v = li.inflate(R.layout.alertlayout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(v);
builder.setCancelable(false);
builder.setPositiveButton("Create", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText title = (EditText) v.findViewById(R.id.ettitle);
EditText snippet = (EditText) v.findViewById(R.id.etsnippet);
String s = title.getText().toString();
String ss = snippet.getText().toString();
googlemap.addMarker(new MarkerOptions()
.title(s)
.snippet(ss)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))
.position(latlng)
);
}
});
//Create Negative button
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}