This is my GoogleMapAPI, I wish user can type the Marker information first, and then use that to make the marker.
But LogCat always say "String MarkerInfo = markerInfo.getText().toString();" Fail.
Sorry I'm a newbie for coding. Please help me.
public void onMapLongClick(final LatLng point) {
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setTitle(R.string.funtion);
builder1.setItems(choice, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int selectedItem) {
Toast.makeText(MainActivity.this,"You Select Letter "+choice[selectedItem],Toast.LENGTH_SHORT).show();
dialog.dismiss();
if(selectedItem==1){
AlertDialog.Builder builder2;
Context mContext = MainActivity.this;
LayoutInflater inflater = getLayoutInflater();
builder2 = new AlertDialog.Builder(mContext);
markerInfo = (EditText)findViewById(R.id.markerInfo);
builder2.setView(inflater.inflate(R.layout.markerinfo, null))
.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface marker, int id) {
String MarkerInfo = markerInfo.getText().toString();
map.addMarker(new MarkerOptions()
.position(point)
.title(MarkerInfo)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface marker, int id) {
}
});
builder2.setTitle(R.string.typeinfo);
AlertDialog marker = builder2.create();
marker.show();
}
}
});
AlertDialog alert = builder1.create();
alert.show();
}
Looks like R.id.markerInfo is declared insido markerinfo.xml
, so you have to use the "inflated" version of markerinfo.xml
to retrieve the EditText
View view = inflater.inflate(R.layout.markerinfo, null);
markerInfo = (EditText)view.findViewById(R.id.markerInfo);
builder2.setView(view);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.